#include <strstream>
#include <iostream>
using namespace std;
void main()
{
     strstream ss;
    ss << "hello" << ends;
    cout << ss.str() << endl;
    ss.seekp(0, ios::beg);
    ss << "ok" << ends;
    cout << ss.str() << endl;
}在vc下编译运行,
结果如下:
Hello
Hello
请问为什么不是
ok

解决方案 »

  1.   

    你用缺省构造函数生成strstream对象,那么调用str()会导致他的
    BUFFER冻结,也就是ss << "ok" << ends;不起作用了,所以结果是
    Hello
    Hello
    调用 rdbuf->freeze( 0 ).去解冻该BUFFER。
      

  2.   

    thx.
    那在什么情况下Buffer不会被冻结?
    冻结有什么意义?
      

  3.   

    If a strstreambuf object has a dynamic array, memory is usually deleted on destruction and size adjustment. The freeze function provides a way to prevent that automatic deletion. Once an array is frozen, no further input or output is permitted. The results of such operations are undefined.
    更详细的内容请查看MSDN。