vendredi 18 août 2017

Filewrite not happening when ofstream pointer is in a std::map in C++

WRT below code, it compiles fine & also executes without any exception. But no content gets written to the javascript file. It's 0 bytes.

std::map<std::string, std::shared_ptr<std::ofstream>> m_jsTabFilesMap;
m_jsTabFilesMap.insert({ fileKey, std::make_shared<std::ofstream>(jsFilename) });
auto jsFile = m_jsTabFilesMap[tabName];
(*jsFile).open(tabName + ".js");
*jsFile << contentofJSFile;  // write to JS file

Not sure what did i miss, how do i make it write to file.

Aucun commentaire:

Enregistrer un commentaire