streambuf::sgetc
int sgetc ( );
streambuf
  cplusplus.com  

Get current character.
  The member function returns the character at current get position, or EOF if the get position is the end of the input sequence.

Parameters.

none
 

Return Value.
  The character available at the get position.
  EOF if the get pointer is at the end of the input sequence.

Example.

// show file content - sgetc () example
#include <iostream>
#include <fstream>
using namespace std;

int main () {

  char ch;
  streambuf * pbuf;
  ifstream istr ("test.txt");

  pbuf = istr.rdbuf();

  while (pbuf->sgetc()!=EOF)
  {
     ch = pbuf->sbumpc();
     cout << ch;
  }

  istr.close();

  return 0;
}
This example shows the content of a file on screen, using a combination of sgetc and sbumpc to read the input file.

Basic template member declaration ( basic_streambuf<charT,traits> ):
typedef traits::int_type int_type;
int_type sgetc ( );

See also.
  snextc, sbumpc, sgetn, sputc
  streambuf class


© The C++ Resources Network, 2001