Kommentar
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
Extracts up to _Count characters from the input buffer and stores them in the provided buffer _Ptr.
streamsize _Sgetn_s(
char_type *_Ptr,
size_t _Ptr_size,
streamsize _Count
);
Parameters
_Ptr
The buffer to contain the extracted characters._Ptr_size
The size of _Ptr._Count
The number of elements to read.
Return Value
The number of elements read.
Remarks
The member function returns basic_streambuf::_Xsgetn_s(_Ptr, _Ptr_size, _Count).
Example
// basic_streambuf__Sgetn_s.cpp
// compile with: /EHsc
#include <iostream>
#include <fstream>
int main()
{
using namespace std;
ifstream myfile("basic_streambuf__Sgetn_s.txt", ios::in);
const int BUFSIZE = 10;
char a[BUFSIZE];
// Extract 3 characters from myfile and store them in a.
streamsize i = myfile.rdbuf()->_Sgetn_s(&a[0], BUFSIZE, 3);
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;
}
Input: basic_streambuf__Sgetn_s.txt
testing
Output
3 tes
ting
Requirements
Header: <streambuf>
Namespace: std
See Also
Reference
Safe Libraries: Standard C++ Library