|
Change (ch = getchar ())! = EOF to
(ch = getchar ())! = '\n'
EOF is used to read files, such as text.txt
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main () {
ifstream file;
string line;
file.open ("text.txt");
int row = 1;
while (! file.eof ()) {
getline (file, line);
cout << row << "" << line;
row ++;
cout << endl;
}
file.close ();
system ("pause");
} |
|