Detecting EOF in C++ from a file redirected to STDIN

前端 未结 3 1782
暗喜
暗喜 2020-12-17 06:20

Executing the command:

./program < input.txt

with the following code checking:

string input;
while(cin) {
  getline(cin,         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-17 07:08

    How about this:

    string input;
    while(getline(cin, input)) {
      //do something with input...
    }
    

提交回复
热议问题