There is a text file I want to display, but I only get the first line, not sure how to do this:
string line; ifstream myfile; myfile.open("myfile.txt"); getline(myfile, line); cout << line << endl; There is a text file I want to display, but I only get the first line, not sure how to do this:
string line; ifstream myfile; myfile.open("myfile.txt"); getline(myfile, line); cout << line << endl; string line; ifstream myfile; myfile.open("myfile.txt"); if(!myfile.is_open()) { perror("Error open"); exit(EXIT_FAILURE); } while(getline(myfile, line)) { cout << line << endl; } You just need to add a loop to get all lines of the file
You are reading line just once with one call of getline(myfile, line); You need to do that in a loop until all lines are read. Same question