Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Using the ifstream class to read data from the disk back into your program.
ifstream inFile("data.txt");
string word;
while (inFile >> word) {
cout << word << endl;
}
inFile.close();string line;
while (getline(inFile, line)) {
cout << line << endl;
}The loop while(inFile >> x) automatically stops when it hits the End of File (EOF).
If the file doesn't exist, is_open() will return false. Always check this first!