std::basic_filebuf<CharT,Traits>::pbackfail
From cppreference.com
< cpp | io | basic filebuf
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Input/output library
Print functions (C++23)
Buffers
(C++23)
(C++98/26*)
(C++20)
Streams
Abstractions
File I/O
String I/O
Array I/O
(C++23)
(C++23)
(C++23)
(C++98/26*)
(C++98/26*)
(C++98/26*)
Synchronized Output
(C++20)
Types
Error category interface
(C++11)
(C++11)
std::basic_filebuf
Public member functions
(C++11)
(C++11)
(C++26)
Protected member functions
basic_filebuf::pbackfail
Non-member functions
(C++11)
protected:
virtual int_type pbackfail( int_type c = Traits::eof() )
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), in which case, this function re-reads the file starting one byte earlier and 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 casea) First, checks if there is a putback position, and if there isn't, backs up the get area by re-reading the file starting one byte earlier.
a) 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().b) Otherwise, if the buffer is allowed to modify its own get area, decrements basic_streambuf::gptr() and writes
c to the location pointed to gptr() after adjustment.This function never modifies the file, only the get area of the in-memory buffer.
If the file is not open (is_open()==false, this function returns Traits::eof() immediately.
Contents
[edit] Parameters
c
-
the character to put back, or Traits::eof() to indicate that backing up of the get area is requested
[edit] Return value
c on success except if c was Traits::eof(), in which case Traits::not_eof(c) is returned.
Traits::eof() on failure.
[edit] Example
This section is incomplete
Reason: no example
Reason: no example
[edit] See also
[virtual]
(virtual protected member function of
std::basic_streambuf<CharT,Traits>) [edit]
moves the next pointer in the input sequence back by one
(public member function of
(public member function of
std::basic_streambuf<CharT,Traits>) [edit]
puts one character back in the input sequence
(public member function of
(public member function of
std::basic_streambuf<CharT,Traits>) [edit]