将std::of流的内容复制到std::字符串中



我有一个尚未刷新的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 &

最新更新