0
I looked for some definitions and so far what I know is that the unget()
must return the last character and the putback()
can return other than the last.
But my doubt would be on the functioning. I would like to know the practical uses, why it is used, it returns to where?
I did a test where I entered in a char, gave the unget()
and then I used an input into another variable and I noticed that it filled itself with the returned character and I got a very superficial idea.
I would like you to explain to me this mechanics involving the buffer, the clean after an error and the questions in the second paragraph.
A common use is in lexical parsers - programs that convert a string of characters into a sequence of symbols (tokens). They are used in compilers and others parsers of files in text-based formats (XML, JSON, etc.). The return character operation to read it again allows you to use the input as a stack structure (
get
=pop
,unget
=push
) rather than a simple sequence, simplifying some lexical algorithms.– André Sassi