将std :: ostringstream写入文件而不复制?

vds*_*dsf 3 c++ io

给定一个以输出字符串流作为参数的函数:

void Foo(const std::ostringstream& _oss);
Run Code Online (Sandbox Code Playgroud)

有数据写入流缓冲到一个文件中的任何方式WITHOUT不必调用STR()?

我想避免复制缓冲区(str()会这样做).

void Foo(const std::ostringstream& _oss);
{
  std::ofstream f("foo.bin");

  //WANT: write _oss to f without copying the buffer?
}
Run Code Online (Sandbox Code Playgroud)

sbi*_*sbi 12

operator<<()一个流缓冲区:

f << _oss.rdbuf();
Run Code Online (Sandbox Code Playgroud)

但是,缓冲区需要非常大才能产生明显的差异.通常,无论如何,写入磁盘将占据所需的时间.

请注意,我将避免使用前导下划线创建标识符.