iostream
から を割り当てるとstringbuf
、すべてがうまく機能します
std::stringbuf fb;
std::iostream fs(&fb);
char i = 17, j = 42;
fs.write(&i, 1);
fs.write(&j, 1);
char x, y;
fs.read(&x, 1);
fs.read(&y, 1);
std::cout << (int) x << " " << (int) y << std::endl;
17 42
ただし、stringbuf
a を使用するように変更しようとすると、filebuf
機能しなくなります
std::filebuf fb;
fb.open("/tmp/buffer.dat", std::ios::in | std::ios::out | std::ios::trunc);
std::iostream fs(&fb);
...
0 0
ghex"/tmp/buffer.dat"
には、想定される内容が含まれているとのことです。
filebuf
ファイルを閉じて再度開くことなく、から読み書きすることは可能ですか?