O'Reilly logo

Object Oriented Programming with C++, Second Edition by Sunil Patekar, Mahesh Bhave

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

14.4 TEXT FILES

Text files consist of characters. Text files are line oriented. In Windows Operating System, character newline (‘\n’) represents the end of line1. Text files can be opened either for input or for output.

If we want to open a text file for reading, we have to create an object of ifstream class. There are two methods to open a file for reading.

A) Use a suitable2 constructor of ifstream class.

ifstream f1(“salary.txt”);

B) Create a file stream object with default constructor and then call a method open() with it. For example:

ifstream f1;

f1.open(“f1in.txt”);

Here f1 is the object of the class ifstream. It is a user defined name. It calls the member function open() which takes the parameter as file name “f1in.txt” which is also ...

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