I redirected the cin to a .txt file, and I tried to read line by line in the txt file with using while(getline(cin,str)).But i found that the while loop just keeps running and never ends, so what should I do?
I redirected cin and cout through the "run configuration" in eclipse:
My code is:
#include <iostream>
using namespace std;
int main() {
string line;
while(getline(cin, line)){
cout << line << endl;
}
cout << "hello" << endl;
return 0;
}
The problem is I can't get hello in the output.
Aucun commentaire:
Enregistrer un commentaire