描述了一个对象,该对象可通过使用 basic_stringbuf<Elem, Tr, 类的流缓冲区控制元素和编码对象的插入和提取。Alloc
>
语法
template <class Elem, class Tr = char_traits<Elem>, class Alloc = allocator<Elem>>
class basic_stringstream : public basic_iostream<Elem, Tr>
参数
Alloc
allocator 类。
Elem
字符串的基本元素的类型。
Tr
字符串的基本元素上专用的字符特征。
备注
这个类模板描述一个对象,该对象使用 basic_stringbuf<Elem, Tr, 类的流缓冲区,控制插入和提取元素和编码对象的操作,该类具有 Alloc
类型的元素,元素的字符特征由 > 类确定,并且其元素由 Elem
类的分配器进行分配。Tr
Alloc
该对象存储 basic_stringbuf<Elem, Tr, 类的对象。Alloc
>
构造函数
构造函数 | 说明 |
---|---|
basic_stringstream | 构造 basic_stringstream 类型的对象。 |
Typedef
类型名称 | 说明 |
---|---|
allocator_type | 该类型是模板参数 Alloc 的同义词。 |
成员函数
成员函数 | 说明 |
---|---|
rdbuf | 向 pointer <, Elem , Tr Alloc 返回 > 类型的已存储流缓冲区的地址。 |
str | 设置或获取字符串缓冲区中的文本,而无需更改写入位置。 |
要求
标头:<sstream>
命名空间: std
basic_stringstream::allocator_type
该类型是模板参数 Alloc
的同义词。
typedef Alloc allocator_type;
basic_stringstream::basic_stringstream
构造 basic_stringstream
类型的对象。
explicit basic_stringstream(ios_base::openmode _Mode = ios_base::in | ios_base::out);
explicit basic_stringstream(const basic_string<Elem, Tr, Alloc>& str, ios_base::openmode _Mode = ios_base::in | ios_base::out);
参数
_Mode
ios_base::openmode 中的枚举之一。
str
一个 basic_string
类型的对象。
备注
第一个构造函数通过调用 basic_iostream( sb) 来初始化基类,其中 是类 sb
Elem, Tr, < 的存储对象。Alloc
> 它还通过调用 basic_stringbuf<Elem、Tr、Alloc
>(_Mode
)进行初始化sb
。
第二个构造函数通过调用 basic_iostream( sb) 初始化基类。 通过调用 basic_stringbufsb
Elem, Tr, <(_ Str, ),它还可以初始化 Alloc
。>_Mode
basic_stringstream::rdbuf
将 pointer 类型的已存储流缓冲区的地址返回到 basic_stringbufElem, Tr, <。Alloc
>
basic_stringbuf<Elem, Tr, Alloc> *rdbuf() const;
返回值
向 basic_stringbufpointer
Elem, Tr, < 返回 类型的已存储流缓冲区的地址。Alloc
>
示例
basic_stringstream::str
设置或获取字符串缓冲区中的文本,而无需更改写入位置。
basic_string<Elem, Tr, Alloc> str() const;
void str(
const basic_string<Elem, Tr, Alloc>& _Newstr);
参数
_Newstr
新字符串。
返回值
返回 basic_string<Elem, Tr, 类的对象,它的受控序列是 Alloc
控制的序列副本。>*this
备注
第一个成员函数返回 rdbuf ->str。 第二个成员函数调用 rdbuf
->str(_Newstr
)。
示例
请参阅 basic_stringbuf::str,了解使用 str
的示例。