设置或获取字符串缓冲区中的文本,而写入更改位置。
basic_string<Elem, Tr, Alloc> str( ) const;
void str(
const basic_string<Elem, Tr, Alloc>& _Newstr
);
参数
- _Newstr
新字符串。
返回值
basic_string<返回类Elem,Tr,控制会复制序列顺序控制由 *this的 Alloc**>,** 对象。
备注
第一个成员函数返回 basic_string<Elem,Tr,Alloc类的对象>,控制会复制序列顺序控制由 *this。 复制的顺序取决于存储的 stringbuf 模式:
如果 mode & ios_base::out 不为零,并且输出缓冲区中,序列是全部输出缓冲区 (epptr - 以 pbase开头的元素)。pbase
如果 mode & ios_base::in 不为零,并且输入缓冲区中,序列是整个输入缓冲区 (egptr - 以 eback开头的元素)。eback
否则,则副本的序列为空。
第二个成员函数释放 *this控制当前的任何序列。 然后将的副本顺序控制的 _Newstr。 如果 mode & ios_base::in 不为零,将输入缓冲区在序列开始处开始读取。 如果 mode & ios_base::out 不为零,它将输出缓冲区在序列开始处开始编写。
示例
// basic_stringbuf_str.cpp
// compile with: /EHsc
#include <iostream>
#include <sstream>
using namespace std;
int main( )
{
basic_string<char> i( "test" );
stringstream ss;
ss.rdbuf( )->str( i );
cout << ss.str( ) << endl;
ss << "z";
cout << ss.str( ) << endl;
ss.rdbuf( )->str( "be" );
cout << ss.str( ) << endl;
}
要求
页眉: <sstream>
命名空间: std