+ 2

what should we do if we want to store data entered by the user in vector, in c++

we define a vector v (<vector> is included) vector<int> v; if we want to store a data in array as it's first element we simply write:- cin>>arr[0]; so like that only what code should we write to store the data entered by the user in vector #v?

17th Mar 2018, 7:00 PM
Suraj Jha
Suraj Jha - avatar
3 Answers
+ 9
You would need to make a loop - you would need to use push to add to vectors something like dataType array[5] like for(int x =0; x<5; x++){ dataType temp = 0; cin >> temp; array[x] = temp; }
17th Mar 2018, 7:23 PM
Manual
Manual - avatar
+ 4
You're welcome!
19th Mar 2018, 10:07 AM
Manual
Manual - avatar
+ 2
thanks for your suggestion manual.
19th Mar 2018, 5:01 AM
Suraj Jha
Suraj Jha - avatar