Code #include #include using namespace std; int main(void) { vector v; int n[] = { 47, 15, 22, 29, 38, 11, 91 }; int i; // adding data to vector for (i=0; i<7; i++) { cout << "Adding: " << n[i] << '\n'; v.push_back(n[i]); } // displaying the vector using a simple loop cout << "Vector contains: "; for (i=0; i::iterator iter; for(iter = v.begin(); iter!=v.end(); iter++) { cout << *iter << " "; } cout << '\n'; // using some basic vector functions cout << "The size is " << v.size() << '\n'; cout << "The first element is " << v.front() << '\n'; cout << "The last element is " << v.back() << '\n'; // clearing the vector the hard way // v.clear() would be a lot easier // as long as we're backing through the array, // let's display it in reverse order while (!v.empty()) { cout << v.back() << " "; v.pop_back(); } cout << endl; return 0; }