How to cin to a vector

后端 未结 20 2458
萌比男神i
萌比男神i 2020-11-27 14:44

I\'m trying to ask the user to enter numbers that are put into a vector, then using a function call to count the numbers, why is this not working? I am only able to count t

20条回答
  •  遥遥无期
    2020-11-27 15:43

    #include
    #include
    #include
    using namespace std;
    int main()
    {
        vectorV;
        int num;
        cin>>num;
        string input;
        while (cin>>input && num != 0) //enter any non-integer to end the loop!
    {
        //cin>>input;
       V.push_back(input);
       num--;
       if(num==0)
       {
       vector::iterator it;
        for(it=V.begin();it!=V.end();it++)
            cout<<*it<

提交回复
热议问题