开发者

Is there a C++ version of ungetc?

开发者 https://www.devze.com 2023-03-24 11:13 出处:网络
Is the开发者_如何学Gore a C++ version of ungetc? That is, can I put a character back onto an istream?Yes. istream::putback is the same as ungetc except if using unget():

Is the开发者_如何学Gore a C++ version of ungetc?

That is, can I put a character back onto an istream?


Yes. istream::putback is the same as ungetc except if using unget():

You can't lie with unget(). It "ungets" the last-read character. You can lie with putback(c). You can "putback" some character other than the last-read character. Sometimes putting back a character other than the last-read character can be useful.

Also, if the underlying read buffer really does have buffering capability, you can "putback" more than one character. I think ungetc() is limited to one character.


You can put a character back with the istream::putback function. You can even put a different character if you want.


Yes, http://www.cplusplus.com/reference/iostream/istream/putback/

0

精彩评论

暂无评论...
验证码 换一张
取 消