basic_istream::read

数组中读取指定数量的字符并从流存储它们。

此方法有可能,不安全,因为它依赖于调用方检查传递的值是正确的。

basic_istream<Elem, Tr>& read(
    char_type *_Str, 
    streamsize _Count
);

参数

  • _Str
    读取的字符的数组。

  • _Count
    要读取的字符数。

返回值

流 (*this)。

备注

无格式的输入函数提取到 count 元素并将它们存储在数组开头。_Str。 提取停止在早期到达文件尾,setstate情况下,在函数调用 (failbit)。 在任何情况下,则返回 *this。

示例

// basic_istream_read.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;

int main()
{
    char c[10];
    int count = 5;

    cout << "Type 'abcde': ";

    // Note: cin::read is potentially unsafe, consider
    // using cin::_Read_s instead.
    cin.read(&c[0], count);
    c[count] = 0;

    cout << c << endl;
}
  abcdeabcdeType

FakePre-39d546f2207647d5b47688e97bff39ec-2687137bf721494e8c43ea4c016afd8b

要求

页眉: <istream>

命名空间: std

请参见

参考

basic_istream 类

iostream 编程

iostreams 约定