std::basic_istringstream::basic_istringstream
性病:基本[医]StingStream::Basic[医]迎风流
explicit basic_istringstream( ios_base::openmode mode = ios_base::in | (1) | |
---|---|---|
explicit basic_istringstream( const std::basic_string<CharT,Traits,Allocator>& str, ios_base::openmode mode = ios_base::in | (2) | |
basic_istringstream( basic_istringstream&& other | (3) | (since C++11) |
构造新的字符串流。
1%29构造新的底层字符串设备。底层basic_stringbuf对象被构造为basic_stringbuf<Char,Traits,Allocator>(mode | ios_base::in)...
2%29使用str作为基础字符串设备的初始内容。底层basic_stringbuf对象被构造为basic_stringbuf<Char,Traits,Allocator>(str, mode | ios_base::in)...
3%29移动构造函数。构造具有以下状态的字符串流:other
使用移动语义。
参数
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: Constant Explanation app seek to the end of stream before each write binary open in binary mode in open for reading out open for writing trunc discard the contents of the stream when opening ate seek to the end of stream immediately after open |
Constant | Explanation | |
app | seek to the end of stream before each write | |
binary | open in binary mode | |
in | open for reading | |
out | open for writing | |
trunc | discard the contents of the stream when opening | |
ate | seek to the end of stream immediately after open | |
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
二次
另见
str | gets or sets the contents of underlying string device object (public member function) |
---|---|
(constructor) | constructs a basic_stringbuf object (public member function of std::basic_stringbuf) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。