我尝试使用 boost::iostreams 构建一个用于读取和写入 char* 的流缓冲区:
class MemBuf : public std::streambuf
{
public:
MemBuf(char* s, std::size_t n)
{
setg(s, s, (char*)s+ n);
}
};
阅读效果很好:
char myreadBuff[100];
myreadBuff[0] = 'a';
MemBuf mb (myreadBuff, 100);
istream istr (&mb);
cout << istr;
但写作不起作用:
char mywriteBuff[100];
MemBuf mb(mywriteBuff, 100);
ostream ostr($mb);
ostr << "hello world";
cout << mywriteBuff;
什么不见了?
谢谢