Standard C++ Library Class Reference
 {
 vector<int> d;
 int total = 0;
 //
 // Collect values from cin until end of file
 // Note use of default constructor to get ending iterator
 //
 cout << "Enter a sequence of integers (eof to quit): " ;
 copy(istream_iterator<int,vector<int>::difference_type>(cin),
 istream_iterator<int,vector<int>::difference_type>(),
 inserter(d,d.begin()));
 //
 // stream the whole vector and the sum to cout
 //
 copy(d.begin(),d.end()-1,ostream_iterator<int>(cout," + "));
 if (d.size())
 cout << *(d.end()-1) << " = " <<
 accumulate(d.begin(),d.end(),total) << endl;
 return 0;
 }
Warning
If your compiler does not support default template parameters, then you will need to always
supply the Allocator template argument. For instance, you'll have to write :
vector<int, allocator>
instead of :
vector<int>
See Also
Iterators, ostream_iterator










