cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : streambuf : snextc
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
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::snextc public member function
int snextc ( );

Increase get pointer and return next character

Advances the get pointer one position, and then returns the newly pointed character in the sequence.

During its operation, the function will call the protected virtual member function uflow if the get pointer gptr reaches the end pointer egptr (or if it is a null pointer).

Notice that, although similar, the following functions have different behaviors:

  • sgetc: returns the character pointed by the get pointer.
  • sbumpc: advances the get pointer and returns the character pointed by it before the call.
  • snextc: advances the get pointer and returns the character pointed by it after the call.

Parameters

none

Return Value

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

Example

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

int main () {

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

  pbuf = istr.rdbuf();

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

  istr.close();

  return 0;
}

This example shows the content of a file on screen, using the combination of sgetc and snextc to read the input file.

Basic template member declaration

( basic_streambuf<charT,traits> )
typedef traits::int_type int_type;
int_type snextc ( );

See also

streambuf::sbumpc Get current character and increase get pointer (public member function)
streambuf::sgetc Get current character (public member function)
streambuf::sgetn Get sequence of characters (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us