Q: Is there a similar way to read integer pairs from stdin to vector > in C++ I am wondering if there is a way as slick as the following
copy(istream_iterator<int>(cin), istream_iterator<int>(),back_inserter(v));

to copy pairs of int into a vector<pair<int,int> > when the input is given in pairs in the order of their appearance?
Thanks.

A: boost::zip_iterator could be used.
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));


A: You can do this – but you need to write your own operator >> for the pair class first. This operator is the whole secret of the above call. Its actual implementation depends on the format of your int pairs.
