我有一个尚未刷新的std::ofstream
对象。有没有办法获取这个ofstream
的内容并将其存储到std::string
中?
我想要的基本是:
std::ofstream ofs("somefile.txt");
ofs << "stuff";
someMethod(ofs); //This method streams into ofs as well
ofs <<"blah";
yetAnotherMethod(ofs); //ofs gets violated inside this method as well
//more data streamed into ofs
std::string s; //Whatever was streamed into ofs should go into s as well for an additional output.
否"该CCD_ 4〃的内容;是荒谬的。文件有内容,流是表示向文件写入的句柄。
刷新ofs
并读取文件,或者使用std::ostream &
代替std::ofstream &
。