|
|
The char extractor skips whitespace. Programs frequently need to read the next character whether or not it is whitespace. This can be done with the get() member function. For example,
char c; cin.get(c);
get() returns the istream and a common idiom is:
char c ; while ( cin.get(c) ) { ... }
Programs also occasionally need to read binary values (e.g., those written with write()) and this can be done with the read() member function.
cin.read((char*)&x,sizeof(x)) ;This does the inverse of the earlier write example (namely, it inputs the raw binary form of x).
If a program is doing a lot of character binary input, it may be more efficient to use the lower level part of the iostream library (streambuf classes) directly rather than through streams.