描述了控制元素和编码对象插入 basic_stringbuf<Elem, Tr, 类的流缓冲区的对象。Alloc>
语法
template <class Elem, class Tr = char_traits<Elem>, class Alloc = allocator<Elem>>
class basic_ostringstream : public basic_ostream<Elem, Tr>
参数
Alloc
allocator 类。
Elem
字符串的基本元素的类型。
Tr
字符串的基本元素上专用的字符特征。
注解
该类描述了控制元素和编码对象插入流缓冲区的对象(其字符特征由 Elem 类确定,其元素由 Tr 类的分配器分配),该流缓冲区具有 Alloc 类型的元素。 该对象存储 basic_stringbuf<Elem, Tr, 类的对象。Alloc>
构造函数
| 构造函数 | 说明 |
|---|---|
| basic_ostringstream | 构造 basic_ostringstream 类型的对象。 |
Typedef
| 类型名称 | 说明 |
|---|---|
| allocator_type | 该类是模板参数 Alloc 的同义词。 |
成员函数
| 成员函数 | 说明 |
|---|---|
| rdbuf | 向 pointer<, Elem, TrAlloc 返回 > 类型的已存储流缓冲区的地址。 |
| str | 设置或获取字符串缓冲区中的文本,而无需更改写入位置。 |
要求
标头:<sstream>
命名空间: std
basic_ostringstream::allocator_type
该类是模板参数 Alloc 的同义词。
typedef Alloc allocator_type;
basic_ostringstream::basic_ostringstream
构造 basic_ostringstream 类型的对象。
explicit basic_ostringstream(ios_base::openmode _Mode = ios_base::out);
explicit basic_ostringstream(const basic_string<Elem, Tr, Alloc>& str, ios_base::openmode _Mode = ios_base::out);
参数
_Mode
ios_base::openmode 中的枚举之一。
str
一个 basic_string 类型的对象。
注解
第一个构造函数通过调用 basic_ostream( sb ) 初始化基类,其中 sb 是 basic_stringbuf< Elem, Tr, Alloc> 类的存储对象。 它还可以通过调用 sb 来初始化 basic_stringbuf< Elem, Tr, Alloc>( _Mode | ios_base::out )。 有关详细信息,请参阅 basic_ostream 和 basic_stringbuf。
第二个构造函数通过调用 basic_ostream( sb ) 初始化基类。 它还可以通过调用 sb 来初始化 basic_stringbuf< Elem, Tr, Alloc >( str, _Mode | ios_base::out )。
basic_ostringstream::rdbuf
向 pointerElem, Tr, < 返回 类型的已存储流缓冲区的地址。Alloc>
basic_stringbuf<Elem, Tr, Alloc> *rdbuf() const;
返回值
向 basic_stringbufpointerElem, Tr, < 返回 类型的已存储流缓冲区的地址。Alloc>
注解
成员函数将 pointer 类型的已存储流缓冲区的地址返回到 basic_stringbuf<Elem, Tr, Alloc>。
示例
basic_ostringstream::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 的示例。