detecting end of input with cin

前端 未结 6 1486
梦毁少年i
梦毁少年i 2020-12-10 06:13

I want to read a line of integers from the user. I\'m not sure how to check to see if the input has ended. For example I want to be able to do something like



        
6条回答
  •  忘掉有多难
    2020-12-10 06:55

    using fstream you can do something like this

    ifstream ifile("input.txt");
    while(!ifile.eof())
    {
        /* do something */
    }
    

    you can also use this

    if(!ifile.is_open())
    {
       /* do something */
    }
    

提交回复
热议问题