Saturday, December 4, 2010


Given:vector<int> v;copy(v.begin(), v.end(), cout);

For the above statement to work, there needs to be ostream_iterator<int>() wrapped around the cout.

copy() needs the third argument to be an output iterator. cout is a stream, and ostream_iterator<int>() returns an output iterator that accepts integers via operator=() and translates them into calls to operator>>().

No comments:

Post a Comment