+ 3

How do you put input into a vector when you don't know how many elements there will be for input?

I tried string temp; cin >> temp; while(temp != NULL) but I received an error for the while statement.

24th Dec 2019, 9:53 PM
Julio Castaneda
Julio Castaneda - avatar
3 Réponses
+ 3
Thank you! This is perfect!
24th Dec 2019, 11:34 PM
Julio Castaneda
Julio Castaneda - avatar
+ 1
edited: in my previous version...the vector length would be 1 larger than the actual input. vector<string> myvector; string mystring; while (true){ getline(cin, mystring); if (mystring == "") break; myvector.push_back(mystring); }
24th Dec 2019, 11:39 PM
rodwynnejones
rodwynnejones - avatar
0
@Alexandr Are you sure that your code works? I've ran it (thinking..."ohhh that's handy to know")...on my IDE (code::blocks)...but It never comes out of the loop.
25th Dec 2019, 12:00 AM
rodwynnejones
rodwynnejones - avatar