public member function
<streambuf> <iostream>

std::streambuf::sbumpc

int sbumpc();
Get current character and advance to next position
Returns the character at the current position of the controlled input sequence, and advances the position indicator to the next character.

Notice that, although similar, the following member functions have different behaviors:
member functiondescription
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.

Internally, the function calls the virtual protected member uflow if there are no read positions available at the get pointer (gptr). Otherwise, the function uses the get pointer (gptr) directly, without calling virtual member functions.

Its behavior is the same as if implemented as:
1
2
3
4
5
int sbumpc() {
  if ( (!gptr()) || (gptr()==egptr()) ) return uflow();
  gbump(1);
  else return gptr()[-1];
}

Return Value

The character at the current position of the controlled input sequence before the call, as a value of type int.
If there are no more characters to read from the controlled input sequence, the function returns the end-of-file value (EOF).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// show file content - sbumpc() example
#include <iostream>     // std::cout, std::streambuf
#include <fstream>      // std::ifstream
#include <cstdio>       // EOF

int main () {
  std::ifstream istr ("test.txt");
  if (istr) {
    std::streambuf * pbuf = istr.rdbuf();
    while ( pbuf->sgetc() != EOF )
    {
      char ch = pbuf->sbumpc();
      std::cout << ch;
    }
    istr.close();
  }
  return 0;
}

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

Data races

Modifies the stream buffer object.
Concurrent access to the same stream buffer object may introduce data races.

Exception safety

Basic guarantee: if an exception is thrown, the stream buffer is in a valid state (this also applies to standard derived classes).

See also