basic_streambuf::snextc
basic_streambuf::snextc
To retrieve the next character in a stream.
int_type snextc();
The function
snextc() calls
sbumpc() to extract the next character in a stream. After the operation, the get pointer references the character following the last character extracted.
If sbumpc returns
traits::eof, otherwise returns
sgetc().
#include <iostream>
#include <sstream>
const int size = 100;
int main()
{
using namespace std;
stringbuf strbuf;
strbuf.pubsetbuf('\0', size);
strbuf.sputn("ABCDE",50);
char ch;
// look ahead at the next character
ch =strbuf.snextc();
cout << ch;
// get pointer was not returned after peeking
ch = strbuf.snextc();
cout << ch;
return 0;
}
Result:
BC