到 _Count 字符中提取输入从缓冲区并在提供的缓冲区 _Ptr存储它们。
此方法有可能,不安全,因为它依赖于调用方检查传递的值是正确的。
streamsize sgetn(
char_type *_Ptr,
streamsize _Count
);
参数
_Ptr
包含提取的字符的缓冲区。_Count
元素的数目。读取的。
返回值
元素读取的数字。 有关更多信息,请参见streamsize。
备注
成员函数返回 xsgetn(_Ptr,_Count)。
示例
// basic_streambuf_sgetn.cpp
// compile with: /EHsc /W3
#include <iostream>
#include <fstream>
int main()
{
using namespace std;
ifstream myfile("basic_streambuf_sgetn.txt", ios::in);
char a[10];
// Extract 3 characters from myfile and store them in a.
streamsize i = myfile.rdbuf()->sgetn(&a[0], 3); // C4996
a[i] = myfile.widen('\0');
// Display the size and contents of the buffer passed to sgetn.
cout << i << " " << a << endl;
// Display the contents of the original input buffer.
cout << myfile.rdbuf() << endl;
}
Enter:basic_streambuf_sgetn.txt
testing
Output
3 tes
ting
要求
页眉: <streambuf>
命名空间: std