C++密钥和文件的映射不起作用

C++ map of a key and file doesn't work

本文关键字:映射 不起作用 文件 密钥 C++      更新时间:2023-10-16

我想在C++中创建密钥和相应文件的映射。我使用了下面的狙击手,它在最后一行给出了平均异常*m_jsTabFilesMap[key] << text;

std::map<std::string, std::ofstream*> m_jsTabFilesMap;
std::string text = "hello all";
std::string key = "a";
*m_jsTabFilesMap[key] << text;

显式删除std::ofstream的复制构造函数。您必须通过指针或以不同的方式存储流,如果您希望流对象在映射中,请不要尝试复制流对象。