0

How i can save map of structure in c++ to txt? I have that code.

#include <bits/stdc++.h>
#include <fstream>
using namespace std;

struct category {
        int id;
        std::string name;
};

map<int, category> categories;

int main() {
        category tmp1 = { 1, "First category" };
        category tmp2 = { 2, "Second category" };

        categories[1] = tmp1;
        categories[2] = tmp2;
        fstream file;
        file.open("test.txt", ios::out, ios::app);
        file << categories[1] << endl << categories[2];
        file.close();
}

I have error in vscode but i cant read it.

boldog
  • 1
  • 2

0 Answers0