在线文档教程
C++
输入/输出 | Input/output

std::istrstream::istrstream

Std::朝流::

explicit istrstream(const char* s(1)
explicit istrstream(char* s(2)
istrstream(const char* s, std::streamsize n(3)
istrstream(char* s, std::streamsize n(4)

构造新的StStream及其基础std::strstreambuf...

1,2%29构造基础std::strstreambuf打电话strstreambuf(s,0)并使用strStrebuf的地址初始化基类。如果s不是指向以空结尾的数组的元素。

3,4%29构造基础std::strstreambuf打电话strstreambuf(s,n)并使用strStrebuf的地址初始化基类。如果s不是指向至少长度为n元素。

参数

s-C-string or char array to use as the contents of the stream
n-size of the array

二次

#include <iostream> #include <strstream> int main() { std::istrstream s1("1 2 3" // string literal int n1,n2,n3; if(s1 >> n1 >> n2 >> n3) std::cout << n1 << ", " << n2 << ", " << n3 << '\n'; char arr[] = {'4', ' ', '5', ' ', '6'}; std::istrstream s2(arr, sizeof arr if(s2 >> n1 >> n2 >> n3) std::cout << n1 << ", " << n2 << ", " << n3 << '\n'; }

二次

产出:

二次

1, 2, 3 4, 5, 6

二次

另见

(constructor)constructs a strstreambuf object (public member function of std::strstreambuf)
(constructor)constructs an strstream, optionally allocating the buffer (public member function of std::ostrstream)
(constructor)constructs an strstream, optionally allocating the buffer (public member function of std::strstream)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/io/strstream/strstream