Export (0) Print
Expand All

basic_streambuf::_Sgetn_s 

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.

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

testing

Output

3 tes
ting

Header: <streambuf>

Community Additions

ADD
Show:
© 2014 Microsoft