int_type sgetc();
| member function | description |
|---|---|
sgetc() | returns the character at the current position. |
sbumpc() | returns the character at the current position and advances the current position to the next character. |
snextc() | advances the current position to the next character and returns this next character. |
1
2
3
4
int_type sgetc() {
if ( (!gptr()) || (gptr()==egptr()) ) return underflow();
else return traits_type::to_int_type(*gptr());
}
traits_type::eof() ).1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// show file content - sgetc() example
#include <iostream> // std::cout, std::streambuf
#include <fstream> // std::ifstream
int main () {
std::ifstream istr ("test.txt");
if (istr) {
std::streambuf * pbuf = istr.rdbuf();
do {
char ch = pbuf->sgetc();
std::cout << ch;
} while ( pbuf->snextc() != std::streambuf::traits_type::eof() );
istr.close();
}
return 0;
}