Partager via


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.

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

Concepts

basic_streambuf Class

basic_streambuf Members

iostream Programming

iostreams Conventions

Safe Libraries: Standard C++ Library