J'essaie d'afficher le contenu d'un map de la même manière que les autres conteneurs, mais une erreur est générée:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
std::map<const int, int> list;
...
std::copy(list.begin(), list.end(), std::ostream_iterator< std::pair<const int, int> >(std::cout, " "));
c:\program files\microsoft visual studio\vc98\include\xutility(19) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct std::pair<int const ,int>' (or there is no acceptable conversion)
d:\travail\yg\exemples\win32console\main.cpp(35) : see reference to function template instantiation 'class std::ostream_iterator<int,char,struct std::char_traits<char> > __cdecl std::copy(class std::_Tree<int const ,struct std::pair<int cons
t ,int>,struct std::map<int const ,int,struct std::less<int const >,class std::allocator<int> >::_Kfn,struct std::less<int const >,class std::allocator<int> >::iterator,class std::_Tree<int const ,struct std::pair<int const ,int>,struct std::map<int
const ,int,struct std::less<int const >,class std::allocator<int> >::_Kfn,struct std::less<int const >,class std::allocator<int> >::iterator,class std::ostream_iterator<int,char,struct std::char_traits<char> >)' being compiled
Edit:

Pour ostream_iterator, apparemment je dois redéfinir l'operateur <<