/* CS19 C++ Spring 2004 * vectorex.cpp (STL vector example) * Steve J. Hodges */ #include #include #include #include using namespace std; main(){ vector iv; int temp; for(int i=0; i<11; i++){ iv.push_back(i); } //while( iv.size() > 0){ // iv.pop_back(); /* remove item from back */ // } // iv.clear(); /* erase entire vector */ // iv[5] = 567; /* demonstrating direct element access */ cout << "size:" << iv.size() << " capacity: " << iv.capacity() << endl; std::vector::const_iterator iter; for(iter=iv.begin(); iter != iv.end(); iter++){ cout << *iter << " "; // (*iter)++; /* modification - not allowed for const operator */ } cout << endl; // another way to print the whole vector copy(iv.begin(), iv.end(), ostream_iterator(cout, " ") ); cout << endl; }