rdbuf()不能使用在stringstream和fstream

2013年6月12日 由 Creater 留言 »

先来看看原型:

streambuf* rdbuf ( ) const;
streambuf* rdbuf ( streambuf* sb );

再来看看cplusplus上面的描述

The first form (1) returns a pointer to the stream buffer object currently associated with the stream.

The second form (2) also sets the object pointed by sb as the stream buffer associated with the stream and clears the error state flags.

If sb is a null pointer, the function automatically sets the badbit error state flags (which may throw an exception if member exceptions has been passed badbit).

Some derived stream classes (such as stringstream and fstream) maintain their own internal stream buffer, to which they are associated on construction. Calling this function to change the associated stream buffer shall have no effect on that internal stream buffer: the stream will have an associated stream buffer which is different from its internal stream buffer (although input/output operations on streams always use the associated stream buffer, as returned by this member function).

像stringstream和fstream这样的派生类拥有自己的内部缓冲区,是在对象构造时就分配。调用函数streambuf* rdbuf ( streambuf* sb )将不会对内部缓冲区有作用。

广告位

发表评论

你必须 登陆 方可发表评论.