detecting end of input with cin

前端 未结 6 1473
梦毁少年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 07:09

    Yo have to do the following

    int temp;
    
    vector v;
    while(cin>>temp){
        v.push_back(temp);
    }
    

    also you can check for end of input using

    if(cin.eof()){
        //end of input reached
    }
    

提交回复
热议问题