std::basic_stringbuf<CharT,Traits,Allocator>::pbackfail
protected: virtual int_type pbackfail( int_type c = Traits::eof() ) |
This protected virtual function is called by the public functions basic_streambuf::sungetc and basic_streambuf::sputbackc (which, in turn, are called by basic_istream::unget and basic_istream::putback).
1) The caller is requesting that the get area is backed up by one character (
pbackfail() is called with no arguments or with Traits::eof() as the argument)
a) First, checks if there is a putback position, and if there really isn't, fails. (stringbuf has no external character source to re-read)
b) If the caller was wrong and the putback position is in fact available, simply decrements
basic_streambuf::gptr(), e.g. by calling gbump(-1).
2) The caller attempts to putback a different character from the one retrieved earlier (
pbackfail() is called with the character that needs to be put back), in which case
a) First, checks if there is a putback position, and if there isn't, fails.
b) Then checks what character is in the putback position. If the character held there is already equal to
c, as determined by Traits::eq(to_char_type(c), gptr()[-1]), then simply decrements basic_streambuf::gptr().
c) Otherwise, if the buffer is open for reading only, fails.
d) Otherwise, if the buffer is open for writing (
mode && std::ios_base::out is nonzero), then decrements basic_streambuf::gptr() and writes c to the location pointed to gptr() after adjustment.Параметры
| c | - | символ для возврата, или Traits::eof() для указания, что требуется возврат области получения |
Возвращаемое значение
c при успехе, за исключением случаев, когда c было Traits::eof(), в этом случае возвращается Traits::not_eof(c).
Traits::eof() при ошибке.
Пример
См. также
|
[virtual] |
возвращает символ обратно в последовательность ввода, возможно, изменяя последовательность ввода (виртуальная защищенная функция члена std::basic_streambuf<CharT,Traits>) |
| перемещает указатель на следующий символ в последовательности ввода назад на один (публичная функция члена std::basic_streambuf<CharT,Traits>) |
|
| возвращает один символ обратно в последовательность ввода (публичная функция члена std::basic_streambuf<CharT,Traits>) |
|
| возвращает символ (публичная функция члена std::basic_istream<CharT,Traits>) |
|
| помещает символ в поток ввода (публичная функция члена std::basic_istream<CharT,Traits>) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/io/basic_stringbuf/pbackfail