std::basic_ostringstream::basic_ostringstream
来自cppreference.com
< cpp | io | basic ostringstream
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
basic_ostringstream( ios_base::openmode mode = ios_base::out ); |
(1) | |
basic_ostringstream( const std::basic_string<CharT,Traits,Allocator>& str, ios_base::openmode mode = ios_base::out ); |
(2) | |
basic_ostringstream( basic_ostringstream&& other ); |
(3) | (C++11 起) |
构建新的字符串流.
1) 构建新的基础字符串设备。底层
2) basic_stringbuf
对象被构造为basic_stringbuf<Char,Traits,Allocator>(mode | ios_base::out).原文:
Constructs new underlying string device. The underlying
basic_stringbuf
object is constructed as basic_stringbuf<Char,Traits,Allocator>(mode | ios_base::out).使用复制的
3) str
的基础字符串设备的初始内容。底层basic_stringbuf
对象被构造为basic_stringbuf<Char,Traits,Allocator>(str, mode | ios_base::out).原文:
Uses a copy of
str
as initial contents of the underlying string device. The underlying basic_stringbuf
object is constructed as basic_stringbuf<Char,Traits,Allocator>(str, mode | ios_base::out).移动的构造函数。构建文件流的状态
other
使用移动语义. 原文:
Move constructor. Constructs the file stream with the state of
other
using move semantics. [编辑] 参数
str | - | 使用字符串的字符串流的初始内容
原文: string to use as initial contents of the string stream | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mode | - | 指定流的开放模式。这是位掩码类型,有以下常量的定义:
原文: specifies stream open mode. It is bitmask type, the following constants are defined:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
other | - | 另一个字符串流作为源使用
原文: another string stream to use as source |
[编辑] 为例
#include <iostream> #include <sstream> int main() { // default constructor (input/output stream) std::stringstream buf1; buf1 << 7; int n = 0; buf1 >> n; std::cout << "buf1 = " << buf1.str() << " n = " << n << '\n'; // input stream std::istringstream inbuf("-10"); inbuf >> n; std::cout << "n = " << n << '\n'; // output stream in append mode (C++11) std::ostringstream buf2("test", std::ios_base::ate); buf2 << '1'; std::cout << buf2.str() << '\n'; }
输出:
buf1 = 7 n = 7 n = -10 test1
[编辑] 另请参阅
获取或设置字符串设备对象相关的内容 原文: gets or sets the contents of underlying string device object (公共成员函数) | |
构造一个的basic_stringbuf对象 (公共成员函数of std::basic_stringbuf )
|