I'm trying to create a vector of ofstream but it doesn't work.
std::vector<std::ofstream> files(10);
The program stops working after this line.
auto createFiles(int n)
{
std::vector<std::ofstream> files;
for(int i=0; i<n; ++i)
{
std::string fileName("Card" + toString(i+1) + ".txt");
files.emplace_back(fileName);
if(!files[i]) throw std::runtime_error("Could not open file " + fileName);
}
return files;
}
I've tried this way but it doesn't work either. (the program stops working after the first execution of files.emplace_back(fileName);)
Aucun commentaire:
Enregistrer un commentaire