+ 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?
3 Antworten
+ 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;
}
+ 4
You're welcome!
+ 2
thanks for your suggestion manual.