To create a file, use either the ifstream or fstream class, and specify the name of the file. To read to the file.
The C++ program demonstrates how to read a file using fstream in C++.
The program first declares a string variable myText which will be used to store the lines read from the file. Then an input file stream object MyReadFile is created with the file name "test.txt". The program then enters a while loop that reads each line of the file using the getline() function until there are no more lines to be read. Each line is stored in the myText variable and printed to the console using cout. Finally, the input file stream is closed using the close() function.
#include<iostream> #include<fstream> using namespace std; //Read a File using C++ fstream int main() { string myText; ifstream MyReadFile("test.txt"); while(getline(MyReadFile,myText)) { cout << myText<<endl; } MyReadFile.close(); return 0; }
On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document.To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions