I'm using istream::get() to read characters from a stream. The issue is that when you read the EOF character, get
sets the failbit.
I want to keep the stream clean, because there really hasn't been an error, but I do want to keep the eofbit
set.
How do you keep the current state of the stream, but unset the failbit. I'm having issues understanding the differences between setstate and clear and how to use them to "unset" a bit on the stream.
2条答案
按热度按时间klr1opcd1#
To remove a single flag some the streams state is a two part process. First you need to get that current state of the stream with
rdstate()
and then do bitwise operations on that returned state to clear the flags you want. Then you can callclear()
and pass the new state to that to have it set the state of the stream. You can see all of this working with this live example :output:
aiazj4mn2#
想明白了。我相信这是正确的方法: