I’m wondering if there’s a way like "
copy(istream_iterator<int>(cin), istream_iterator<int>(),back_inserter(v));
to copy pairs intin vector<pair<int,int> >, when input is given in pairs in the order they appear?
int
vector<pair<int,int> >
Thank.
You can do this, but first you need to write your own operator >>for the pair class. This statement is the whole secret of the aforementioned call. Its actual implementation depends on the format of your int pairs.
operator >>
boost::zip_iterator.
boost::zip_iterator
copy(boost::make_zip_iterator( boost::make_tuple(istream_iterator<int>(cin), istream_iterator<int>(cin)), boost::make_zip_iterator( boost::make_tuple(istream_iterator<int>(), istream_iterator<int>()), back_inserter(v));