如何在c ++中将std :: ofstream对象添加到std :: ofstream对象的地图中?
我尝试过其他相关问题的解决方案,但我一直遇到分段错误。问题发生在我的openFile函数中。
我发现了另一个与此相关的问题,并尝试使用map :: \ templace,但我遇到了分段错误: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";
}