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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access