How Can I Read the Contents of a File
Below the program of how we can read and output the contents of a file using C++
#include <fstream> #include <iostream> #include <string> using namespace std; int main() { string line; ifstream reader("file1.txt"); if (!reader) { cout << "There was an error opening file" << endl; return -1; } while (!reader.eof()) { getline(reader, line); cout << line << endl; } reader.close(); return 0; }