I am reading a book and it says:
To turn off a single condition, we use the
rdstate
member and the bitwise operators to produce the desired new state.
For example, the following turns offfailbit
andbadbit
but leaveseofbit
untouched:
//turns off failbit and badbit but all other bits unchanged.
cin.clear(cin.rdstate() & ~cin.failbit & ~cin.badbit);
I felt totally confused about what the code does.
Here's how I try to figure out:
Find out what rdstate() returns.
http://en.cppreference.com/w/cpp/io/basic_ios/rdstate.
It returns aiostate
object.Find out what
iostate
object is.
http://en.cppreference.com/w/cpp/io/ios_base/iostate.
It's a Bitmask Type and also I saw it's "/implementation defined/".Find out what Bitmask Type is and how
iostate
implements in my compiler.
http://en.cppreference.com/w/cpp/concept/BitmaskType.
typedef int iostate
, visual c++.
No helpful information. And I got stuck here.
So I still don't have a clue about what rdstate()
returned value looks like and how that line of code work.
How does cin.clear(cin.rdstate() & ~cin.failbit & ~cin.badbit);
work?
Btw, how should I explore something new (in C++), any advice? I mean, I've checked the documentation and I found that's not very helpful. (e.g. Python and JavaScript docs are much easier to read and understand)