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.
B) Create a file stream object with default constructor and then call a method open() with it. For example:
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 ...