I have two methods of doing this. First one:
string output;
for (auto& kv : stored) {
output.append(kv.second + "\n");
}
insert(file, output);
where insert() is:
void insert(string file, string str) {
ifstream stream(file);
stream << str;
stream.close();
}
Second method:
ifstream stream(file);
for(auto& kv : stored) {
stream << kv.second;
}
stream.close();
where in both cases, stored is of type map<int, string>
Which method is more efficient?
EDIT: For the people who are telling me this is a duplicate, I want to know what's the most efficient method to use out of the two, not how to do it.
Aucun commentaire:
Enregistrer un commentaire