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

std::basic_istream::readsome

std::streamsize readsome( char_type* s, std::streamsize count );

?

?

提取至count输入流中立即可用的字符。所提取的字符存储在s...

表现为UnformattedInputFunction.在构造和检查哨兵对象之后,

  • 如果rdbuf()->in_avail() == -1,电话setstate(eofbit)不提取字符。
  • 如果rdbuf()->in_avail() == 0,不提取字符。
  • 如果rdbuf()->in_avail() > 0、提取物std::min(rdbuf()->in_avail(), count)字符并将其存储到字符数组的连续位置,该字符数组的第一个元素由s...

参数

s

-

pointer to the character array to store the characters to

count

-

maximum number of characters to read

返回值

实际提取的字符数。

例外

failure如果发生错误%28,则错误状态标志不是goodbit29%和exceptions()将被抛向那个州。

如果内部操作抛出异常,则会捕获该操作,并且badbit已经设定好了。如果exceptions()设置为badbit,异常将被重新抛出。

注记

此函数的行为是高度特定于实现的。例如,当与std::ifstream,一些库实现在打开文件时立即用数据填充底层文件,并在此类实现上读取数据的大约%28%29,可能(但不一定)读取整个文件%29。其他实现仅在请求实际输入操作时从文件读取,而在文件打开后发出的读取约%28%29,则从不提取任何字符%29。同样的,一个呼吁std::cin.readsome()可能会返回所有挂起的未处理控制台输入,或者可能总是返回零而不提取字符。

二次

代码语言:javascript
复制
#include <iostream>
#include <sstream>
 
int main()
{
    char c[10] = {};
    std::istringstream input("This is sample text."); // std::stringbuf makes its entire
                                                      // buffer available for unblocking read
    input.readsome(c, 5); // reads 'This ' and stores in c[0] .. c[4]
    input.readsome(c, 9); // reads 'is sample' and stores in c[0] .. c[8]
    std::cout << c;
}

二次

产出:

二次

代码语言:javascript
复制
is sample

二次

另见

read

extracts blocks of characters (public member function)

in_avail

obtains the number of characters immediately available in the get area (public member function of std::basic_streambuf)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com