【发布时间】:2015-04-30 16:20:05
【问题描述】:
从stringbuf 分配iostream 时,一切正常
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 更改为使用 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读取和写入?
【问题讨论】: