Need guidance!

Hello im not quite understanding why my code wont generate the correct output that i need.

My question is:

Write a program that opens a (text) file, and displays the contents of that file one line at a time. After a line has been displayed, the program should wait for the user to press the key before displaying the next line in the file.

Now when i run and compile my program it just displays everything all at once.. Any suggestions?

using namespace std;
#include <string>
#include <fstream>
#include <iostream>

int main()
ifstream file("input.txt"); // File name goes here
string line;
while(getline(file, line))
cout << line + "\n";
closed account (3qX21hU5)
Should work fine from what I can see. Works just as you described for me (Codeblocks mingGW).







Process returned 0 (0x0)   execution time : 3.042 s
Press any key to continue.
Last edited on
See maybe my issue might be that i was using the compile online website. I seem to have issues tho with using Xcode on my mac when i try and save text file in the programs derived data alias it doesnt open it up like it should in the main program...
Topic archived. No new replies allowed.