streamsize sgetn ( const char * s, streamsize n );

Get some characters.
  Calls protected virtual member xsgetn(s,n), whose default behavior is to get n characters from input sequence and store them in the array pointed by s.


Pointer to a block of memory where the character sequence will be stored.
Number of character to be gotten. This is an object of type streamsize.

Return Value.
  The number of characters got. The value is returned as an object of type streamsize.


// read a file buffer - sgetn () example
#include <iostream>
#include <fstream>
using namespace std;

int main () {

  char content[11];
  streambuf * pbuf;
  ifstream istr ("test.txt");

  pbuf = istr.rdbuf();

  pbuf->sgetn (content,10);


  cout.write (content,10);

  return 0;
This example gets the first ten characters of the file buffer and prints them out.

Basic template member declaration ( basic_streambuf<charT,traits> ):
streamsize sgetn ( char_type* s, streamsize n );

See also.
  sgetc, sputn, sputc
  streambuf class

© The C++ Resources Network, 2001