There is NO operator <<
for std::pair
. You cannot simply use ostream_iterator
with std::pair
.
You can use other things, or write class, that derived from pair
, or that store pair
and use it. You cannot write overloads in std
namespace, since it leads to undefined behaviour and you cannot overload this operator in global namespace, since ADL
will not find correct overload (if you use stl algorithms, like copy
, ostream_iterator
).
Simply, something like this will work well
#include <iostream>
#include <utility>
#include <algorithm>
#include <iterator>
int main()
{
std::vector<std::pair<int, int>> vec =
{
{1,1},
{2,2}
};
for (const auto& p : vec)
{
std::cout << p.first << " " << p.second << std::endl;
}
}