std::istrstream::istrstream
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。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

