C++ examples for STL:vector
Add elements to the end of vector using push_back member function.
#include <iostream> #include <vector> using namespace std; void show(const char *msg, vector<int> vect); int main() {/* w w w . ja v a2 s . c om*/ vector<int> v(10); for(unsigned i=0; i < v.size(); ++i) v[i] = i*i; show("Contents of v: ", v); v.push_back(100); v.push_back(121); show("v after pushing elements onto the end: ", v); cout << endl; return 0; } void show(const char *msg, vector<int> vect) { cout << msg; for(unsigned i=0; i < vect.size(); ++i) cout << vect[i] << " "; cout << "\n"; }