basic_streambuf::sputbackc
Puts a char_type in the stream.
int_type sputbackc(
char_type _Ch
);
Parameters
- _Ch
The character.
Return Value
Returns the character or failure.
Remarks
If a putback position is available and _Ch compares equal to the character stored in that position, the member function decrements the next pointer for the input buffer and returns traits_type::to_int_type(_Ch). Otherwise, it returns pbackfail(_Ch).
Example
// basic_streambuf_sputbackc.cpp
// compile with: /EHsc
#include <iostream>
#include <fstream>
int main( )
{
using namespace std;
ifstream myfile("basic_streambuf_sputbackc.txt",
ios::in);
int i = myfile.rdbuf()->sbumpc();
cout << (char)i << endl;
int j = myfile.rdbuf()->sputbackc('z');
if (j == 'z')
{
cout << "it worked" << endl;
}
i = myfile.rdbuf()->sgetc();
cout << (char)i << endl;
}
Input: basic_streambuf_sputbackc.txt
testing
Output
t
it worked
z
Requirements
Header: <streambuf>
Namespace: std