/* testvector.cpp CIS 150 David Klick 6/28/05 Demonstration of STL vector class. */ #include #include #include #include using std::cout; using std::vector; int main(void) { vector v; // create a vector int i, n; // randomize random number generator srand(time(NULL)); // put 10 random numbers (1-100) into vector for (i=0; i<10; i++) v.push_back(rand() % 100 + 1); // display vector values using at() function for (i=0; i<10; i++) cout << v.at(i) << ' '; cout << '\n'; // display vector values using [] syntax for (i=0; i<10; i++) cout << v[i] << ' '; cout << '\n'; // clear vector one element at a time (from end) while (!v.empty()) { n = v.back(); v.pop_back(); cout << "removed " << n << '\n'; } cout << "Vector now has size " << v.size() << '\n'; return 0; }