Initialize ofstream in constructor class, only working with c++11

拟墨画扇 提交于 2019-12-02 09:23:15

prior to C++11 ofstream has no constructor accepting a std::string. You need the char const* constructor: m_file (outputFilename.c_str())

in C++11, the constructor: explicit ofstream (const string& filename, ios_base::openmode mode = ios_base::out); was added, whereas it is not in previous version.
You need to use the constructor explicit ofstream (const char* filename, ios_base::openmode mode = ios_base::out);

Example:
Out(const std::string& outputFilename) : m_file(outputFilename.c_str(), std::ios_base::out | std::ios_base::app) {}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!