Does any one know how to display a vector after inputing numbers into the vector? Help
Does any one know how to display a vector after inputing numbers into the vector? Help
Do you mean STL vector? If so you can access the vector the same way as an array, using the subscript operators -
vector <int> yourVector(300);
yourVector[0]=10;
cout << yourVector[0];
//etc
if it's a vector like a resizeable array, here's what you do.
This will display each value in your vector on a separate line, assuming ostream<< has been defined for whatever you're storing in your vector. yourVector.size() may vary from vector class to vector class. it's size() in mine, but others use length() or numElements().Code:for (int i(0); i < yourVector.size(); i++){ cout<<yourVector[i]<<"\n"; }