This documentation is archived and is not being maintained.


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



The buffer to contain the extracted characters.


The size of _Ptr.


The number of elements to read.

The number of elements read.

The member function returns basic_streambuf::_Xsgetn_s(_Ptr, _Ptr_size, _Count).

// 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;



3 tes

Header: <streambuf>