Reading from a Text File

Next, let’s examine text file input. It’s based on console input, which has many elements. So let’s begin with a summary those elements:

• You must include the iostream header file.

• The iostream header file defines an istream class for handling input.

• The iostream header file declares an istream variable, or object, called cin.

• You must account for the std namespace; for example, you can use the using directive or the std:: prefix for elements such as cin.

• You can use cin with the >> operator to read a variety of data types.

• You can use cin with the get() method to read individual characters and with the getline() method to read a line of characters at a time.

• You can use cin with methods such as eof() and ...

Get C++ Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.