I am trying to read from stdin using C++, using this code
#include
using namespace std;
int main() {
while(cin) {
getline(cin,
You have not defined the variable input_line
.
Add this:
string input_line;
And add this include.
#include
Here is the full example. I also removed the semi-colon after the while loop, and you should have getline
inside the while to properly detect the end of the stream.
#include
#include
int main() {
for (std::string line; std::getline(std::cin, line);) {
std::cout << line << std::endl;
}
return 0;
}