There is a similar question to this one but it was not answered.
I am trying to create a map of std::ofstream
objects but I cannot build the code.
So far I have tried
//std::map<std::string, std::ofstream> my_files; //this fails
std::map<std::string, std::ofstream& > my_files;
for(auto & member: members){
filename=GetFileName();
//create the file
std::ofstream thefile(filename);
my_files[member.first]=thefile;
}
//Here I use the ofstreams in the map to write etc
I tried the first (commented) line and I got this error. Use of deleted function. So I change it to the line above, but I still get the same error error: use of deleted function ‘std::basic_ofstream<
How can I build a map of ofstream objects?
Note: In the similar question, someone suggested to use a map of strings but the reason to use a map of ofstream is that I am not going to be opening and closing the file everytime I want to do a minimal change to each.