+ 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.
3 Respuestas
+ 3
Thank you! This is perfect!
+ 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);
}
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.