I am trying to read from stdin using C++, using this code
#include <iostream>
using namespace std;
int main() {
while(cin) {
getline(cin, input_line);
cout << input_line << endl;
};
return 0;
}
when i compile, i get this error..
[root@proxy-001 krisdigitx]# g++ -o capture -O3 capture.cpp
capture.cpp: In function âint main()â:
capture.cpp:6: error: âinput_lineâ was not declared in this scope
Any ideas whats missing?
You have not defined the variable
input_line.Add this:
And add this include.
Here is the full example. I also removed the semi-colon after the while loop, and you should have
getlineinside the while to properly detect the end of the stream.