/* File: VectorDriver.cpp * Athr: Dimitri Zarzhitsky * Date: October 16, 2002 * * Desc: provides the basic framework and examples for an introduction to * the STL::vector, iterators, and the algorithms facilities. */ typedef unsigned long ulong; #include #include using std::cout; using std::endl; using std::vector; void fill_vector(vector &data) { for (ulong i=0; i &data) { if (data.empty()) { cout << ""; } else { cout << "<" << data.at(0); for (ulong i=1; i"; } } short compute_sum(const vector &data) { std::vector::const_iterator iter = data.begin(); short sum = 0; while (iter != data.end()) { sum += *iter; iter++; } return sum; } int main() { cout << " ..:: B E G I N S A M P L E C O D E ::.." << endl << endl; vector sample_vector(5); cout << "new vector: "; print(sample_vector); cout << endl; fill_vector(sample_vector); cout << "filled vector: "; print(sample_vector); cout << endl; cout << "sum of vector's elements: " << compute_sum(sample_vector) << endl; cout << endl << " ..:: E N D S A M P L E C O D E ::.." << endl; return 0; }