Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
IOstream Library
manipulators
classes:
filebuf
fstream
ifstream
ios
iostream
ios_base
istream
istringstream
ofstream
ostream
ostringstream
streambuf
stringbuf
stringstream
objects:
cerr
cin
clog
cout
types:
fpos
streamoff
streampos
streamsize
streambuf
streambuf::streambuf
streambuf::~streambuf
public members:
streambuf::getloc
streambuf::in_avail
streambuf::pubimbue
streambuf::pubseekoff
streambuf::pubseekpos
streambuf::pubsetbuf
streambuf::pubsync
streambuf::sbumpc
streambuf::sgetc
streambuf::sgetn
streambuf::snextc
streambuf::sputbackc
streambuf::sputc
streambuf::sputn
streambuf::sungetc
protected members:
streambuf::eback
streambuf::egptr
streambuf::epptr
streambuf::gbump
streambuf::gptr
streambuf::pbase
streambuf::pbump
streambuf::pptr
streambuf::setg
streambuf::setp
virtual prot. members:
streambuf::imbue
streambuf::overflow
streambuf::pbackfail
streambuf::seekoff
streambuf::seekpos
streambuf::setbuf
streambuf::showmanyc
streambuf::sync
streambuf::uflow
streambuf::underflow
streambuf::xsgetn
streambuf::xsputn


streambuf::sgetc

public member function
int sgetc ( );

Get current character

Returns the character currently pointed by the get pointer.

During its operation, the function will call the protected virtual member function underflow if the get pointer gptr points to the same position as the end pointer egptr before the call (or if it is a null pointer).

Unlike the member functions sbumpc and snextc, this function does not advance the get pointer neither before nor after reading it.

Parameters

none

Return Value

The character pointed by the get pointer (type-casted to the appropiate return type).
If the controlled input sequence has exhausted, and underflow could not retrieve more characters, the function returns EOF (or traits::eof() for other traits).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// 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 file.

Basic template member declaration

( basic_streambuf<charT,traits> )
1
2
typedef traits::int_type int_type;
int_type sgetc ( );


See also