O'Reilly logo

C++ Primer Plus by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required