Using Extraction Operators
The latest version of this topic can be found at Using Extraction Operators.
The extraction operator (>>
), which is preprogrammed for all standard C++ data types, is the easiest way to get bytes from an input stream object.
Formatted text input extraction operators depend on white space to separate incoming data values. This is inconvenient when a text field contains multiple words or when commas separate numbers. In such a case, one alternative is to use the unformatted input member function istream::getline to read a block of text with white space included, then parse the block with special functions. Another method is to derive an input stream class with a member function such as GetNextToken
, which can call istream members to extract and format character data.