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;
}
abcde
FakePre-6e7aefb614154378a37bc5d150423fec-eff3e102282c4e30a4febce9c6e6b7d3
需求
標題: <istream>
命名空間: std