<<< State Check Example | Index | Try this! >>> |
What if we need a function that can
check next character;
if necessary, put the character back into the input buffer.
This allows to have functions sensitive to various types of input.
For example, program cin_unget_char.cpp ( download ) illustrates:
stand-alone function named get_value( ) to input a single integer
main( ) function that reports an error to the user. That is, the user dialog is separated from the get_value( ) function.
cin.unget()
call to put the last character back into the input buffer.
cin.clear( ios_base::failbit )
call, which transitions cin object into the state corresponding to cin.fail().
<<< State Check Example | Index | Try this! >>> |