// Print Every Character in a Vector // First, we will fill the vector with characters read from the // standard input. Then, we will print each character. #include #include // has EXIT_SUCCESS #include // has for_each() #include // Print the specified element. void print_element(const char c) { cout << c; return; } int main() { vector v; // make a vector of characters // Store characters from standard input in the vector. char c; while (cin.get(c)) v.push_back(c); // grow vector one larger, storing c // in the last position // Print the vector's characters. // explicitly use iterators, not "for_each(v.begin(), v.end(), print_element);" vector::const_iterator pos;// explicit declaration of an iterator for (pos = v.begin(); pos != v.end(); ++pos) print_element(*pos); return EXIT_SUCCESS; }