public member function
<sstream>

std::basic_istringstream::basic_istringstream

默认 (1)
explicit basic_istringstream (ios_base::openmode which = ios_base::in);
initialization (2)
explicit basic_istringstream (    const basic_string<char_type,traits_type,allocator_type>& str,    ios_base::openmode which = ios_base::in);
默认 (1)
explicit basic_istringstream (ios_base::openmode which = ios_base::in);
initialization (2)
explicit basic_istringstream (    const basic_string<char_type,traits_type,allocator_type>& str,    ios_base::openmode which = ios_base::in);
copy (3)
basic_istringstream (const basic_istringstream&) = delete;
move (4)
basic_istringstream (basic_istringstream&& x);
构造对象
Constructs a basic_istringstream object

(1) 空构造函数 (默认构造函数)
Constructs a basic_istringstream object with an empty sequence as content.
Internally, its basic_istream base constructor is passed a pointer to a basic_stringbuf object constructed with an argument based on which.
(2) initialization constructor
Constructs a basic_istringstream object with a copy of str as content.
Internally, its basic_istream base constructor is passed a pointer to a basic_stringbuf object constructed with arguments based on str and which.
(3) 复制构造函数 (已删除)
已删除 (无复制构造函数)。
(4) move constructor
获取 x 的内容。
First, the function move-constructs both its base basic_istream class from x and a basic_stringbuf object from x's internal basic_streambuf object, and then associates them by calling member set_rdbuf.
x 处于未指定但有效的状态。
It is unspecified whether the sequence controlled by the internal basic_stringbuf object is the one in x before the call, or a copy of it. In any case, both objects have internal string buffers that use independent sequences after the call.
The internal basic_stringbuf object has at least the same duration as the basic_istringstream object.

参数

str
一个具有相同模板参数(charTtraitsAlloc)的basic_string对象,其内容被复制。
x
A basic_istringstream object of the same type (with the same class template parameters charT, traits and Alloc), whose value is moved.
which
Open mode: Access given by the internal basic_stringbuf object to its internal sequence of characters. It is an object of member type openmode for which any combination of the following member values is significant
成员常量代表access
ios_base::in*输入The sequence supports input operations.
ios_base::out输出The sequence supports output operations.
Other values of type ios_base::openmode may also be specified, although whether they have an effect on basic_istringstream objects depends on the library implementation.
成员常量代表access
ios_base::in*输入The sequence supports input operations.
ios_base::out输出The sequence supports output operations.
ios_base::ate在末尾The writing position is at the end after construction, and after every time the content is reset with member str.
Other values of type ios_base::openmode (such as ios_base::app) may also be specified, although whether they have an effect on basic_istringstream objects depends on the library implementation.
* ios_base::in is always set for basic_istringstream objects (even if explicitly not set in argument which).
Note that even though basic_istringstream is an input stream, its internal basic_stringbuf object may be set to also support output operations. This influences certain operations, such as putback, that in basic_istringstream may alter the contents of the sequence.

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// istringstream constructors.
#include <iostream>     // std::cout
#include <sstream>      // std::istringstream
#include <string>       // std::string

int main () {

  std::string stringvalues = "125 320 512 750 333";
  std::istringstream iss (stringvalues);

  for (int n=0; n<5; n++)
  {
    int val;
    iss >> val;
    std::cout << val*2 << '\n';
  }

  return 0;
}

输出
250
640
1024
1500
666


数据竞争

移动构造函数 (4) 会修改 x

异常安全

强保证: 如果抛出异常,则没有副作用。

另见