首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
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)

代码语言:txt
复制
 ? cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com