Put back numbers into input buffer

Suppose a character is called and checked and required to be checked in other function. If I put back that character back into buffer it is good or I should create one more class to hold the value...what is the difference between these two..can anyone explain disadvantages of first if any??
can anyone explain disadvantages of first if any??
You cannot put back more than one character reliably, somebody else can extract it before you.
Generally you only need to ever put back character if you do not need it and it should not be extracted in first place. For example number extracting routine extracts characters until it finds nondigit. As nondigits are not in number extracting function competence, it puts that character back and finishes.

So if you need to use character further, hold on it and pass it further. Do not return it back in stream.
Thanks for the reply..what about if everything in the stream is taken as character.. Is it required to hold the value??... As you described it reads one more and putsback..in math expression, for precedence purpose, it is required put back into the stream for example ( expression)...of course you are talking in general..
what about if everything in the stream is taken as character
Streams hold only characters. THere is no numbers or anything else in streams, only characters. And you can put back only one character.

for precedence purpose, it is required put back into the stream for example ( expression)
Can you provide an example? I do not see where putting back a single character would be useful. In math expression parser you it might be useful to putback character in tokenizing phase: tokenizer reads digit, then another digit, then '+', understands that it belongs to another token and puts it back in stream, because it cannot handle it and should refer it to somebody else.

If you, for example read digit, and want to ensure that it in range 2-5, you should not put it back. It would be wrong thing to do. Putting back is saying: "I took it by mistake, please have it back".
Topic archived. No new replies allowed.