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

Input

iostream input is similar to output. It uses extraction (>>) operators that can be strung together. For example:

   cin >> x >> y ;
inputs two values from the predefined istream cin, which is by default the standard input. The extractor used will be appropriate for the types. The lexical details of numbers are discussed below under ``Format control''. Whitespace characters (spaces, newlines, tabs, form-feeds) will be ignored before x and between x and y. For most types (including all the numeric ones), at least one whitespace character is required between x and y to mark where x ends.

There is a char extractor. For example:

   char c ;
   cin >> c ;

skips whitespace, extracts the next visible character from the istream and stores it in c. (``Non-whitespace'' is too ugly a phrase for extensive use. This document uses ``visible'' instead. Strictly speaking this terminology is incorrect. For example, it classifies control characters as visible. But the term is reasonably euphonious and reasonably clear.)

Sometimes it is desirable to extract the next character unconditionally. For example:

   char c ;
   cin.get(c) ;

The next character is extracted and stored in c, whether or not it is whitespace.
Next topic: User defined extraction operators
Previous topic: Binary output

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004