且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

std :: stringstream和std :: ios :: binary

更新时间:2023-11-12 11:00:34

AFAIK, binary 标志仅适用于 fstream stringstream 从不进行换行,因此这里最无用。

AFAIK, the binary flag only applies to fstream, and stringstream never does linefeed conversion, so it is at most useless here.

此外,传递给 stringstream 的ctor的标志应包含 in out 或两者。在你的case, out 是必要的(或更好的是,使用 ostringstream )否则,流不在输出模式,这就是写入失败的原因。

Moreover, the flags passed to stringstream's ctor should contain in, out or both. In your case, out is necessary (or better yet, use an ostringstream) otherwise, the stream is in not in output mode, which is why writing to it fails.

stringstream ctor的mode参数的默认值为 in | out ,这说明为什么当您不传递任何参数时,操作正常。

stringstream ctor's "mode" parameter has a default value of in|out, which explains why things are working properly when you don't pass any argument.