How to cin to a vector

后端 未结 20 2521
萌比男神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:37

    I ran into a similar problem and this is how I did it. Using &modifying your code appropriately:

       int main()
       {
       int input;
       vector V;
       cout << "Enter your numbers to be evaluated: " 
       << '\n' << "type "done" & keyboard Enter to stop entry" 
       <<   '\n';
       while ( (cin >> input) && input != "done") {
       V.push_back(input);
        }
       write_vector(V);
       return 0;
      }
       
    

提交回复
热议问题