Sorry to rehash old topics, but I couldn't find a relevant post to my question. I have smashed together some code that does what I want, but I'm not quite sure why. The problem I'm trying to solve is printing out text from an input file, redirected to the program using this syntax:
./a.out < input.txt
I understand how to solve this using C, by reading the characters until an EOF value is read in. But this whole stream thing is confusing to me. Here is my current code:
My main questions:Code:#include <iostream> #include <string> using namespace std; int main(){ string line; while( getline( cin , line ) ) { cout << line << endl; } return 0; }
1. What is the return value of the getline function?
2. Is this return value from getline causing the while loop to terminate? Or is there some eof flag magic happening somewhere that I don't know about?