DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
iostream examples

Binary input

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.


Next topic: Creating streams
Previous topic: char* extractor

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005