How should I add std::ofstream objects to a map of std::ofstream objects in c++?
I have tried solutions from other related questions, but I keep getting a segmentation fault. The problem is occurring in my openFile function.
I found another question relating to this, and tried using map::emplace, but I got a segmentation fault: 36817 Segmentation fault: 11
Is it possible to handle std::ofstream with std::map?
#include <fstream>
#include <iostream>
#include <map>
std::map<int, std::ofstream> writeFiles::fileMap = {};
void writeFiles::openFile (int num) {
fileMap.emplace(num, std::ofstream(getName(num))); // This is where the problem is
}
std::string writeFiles::getName (int num) {
return "./temp/matrix/matrix" + std::to_string(num) + ".txt";
}