cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : streambuf : sungetc
- -
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::sungetc public member function
int sungetc ( );

Decrease get pointer

Moves the get pointer one character backwards, making the last character gotten by an input operation available once again for the next input operation.

During its operation, the function will call the protected virtual member function pbackfail if the get pointer gptr points to the same position as the beginning pointer eback.

Parameters

none

Return Value

The value of the character in the new get pointer position.
If the get pointer is at the beginning of the input sequence the function returns EOF (or traits::eof() for other traits).

Example

// sungetc
#include <iostream>
using namespace std;

int main () {

  char ch;
  long n;
  streambuf * pbuf;

  pbuf = cin.rdbuf();

  cout << "Please enter some letters and after a number: ";

  do {
    ch=pbuf->sbumpc();

    if ( (ch>='0') && (ch <='9') )
    {
      pbuf->sungetc ();
      cin >> n;
      cout << "You entered number " << n << endl;
      break;
    }
  } while (ch != EOF);

  return 0;
}

This example gets characters form standard input one by one. When the first numeric digit is found, sungetc is called to restore the position in the stream to that digit in order to be extracted as part of a number using the extraction operator >>.

Basic template member declaration

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

See also

streambuf::sputbackc Put character back (public member function)
streambuf::sgetc Get current character (public member function)
streambuf::snextc Increase get pointer and return next character (public member function)
streambuf::sbumpc Get current character and increase get pointer (public member function)
streambuf::sputc Store character at current put position and increase put pointer (public member function)

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