Why this doesnt't work in C++?
Posted
by
user3377450
on Stack Overflow
See other posts from Stack Overflow
or by user3377450
Published on 2014-06-08T21:18:13Z
Indexed on
2014/06/08
21:24 UTC
Read the original article
Hit count: 124
I'm doing something and I have this:
//main.cpp file
template<typename t1, typename t2>
std::ostream& operator<<(std::ostream& os, const std::pair<t1, t2>& pair)
{
return os << "< " << pair.first << " , " << pair.second << " >";
}
int main()
{
std::map<int, int> map = { { 1, 2 }, { 2, 3 } };
std::cout << *map.begin() << std::endl;//This works
std::copy(map.begin(), map.end(),
std::ostream_iterator<std::pair<int,int> >(std::cout, " "));//this doesn't work
}
I guess this is not working because in the std::copy algorithm the operator isn't defined, but what can I do?
© Stack Overflow or respective owner