Saturday, December 4, 2010

back_inserter

Given:

ifstream myInputFileStream( "input_file.txt" );
vector<string> v;
copy(istream_iterator<string>( myInputFileStream ),istream_iterator<string>(),v);

For the above statement to work, there needs to be a back_inserter() wrapped around the v.

back_inserter() returns an iterator, that calls push_back() on the vector v for each call to its operator=() function.

No comments:

Post a Comment