How to copy maps to ostream_iterators?
I have the following code that I am trying to compile with g++ 3.2 (see
below).
The syntax error messages are telling me there is no function operator<<
defined to accept a std::pair. This is not true: as you can see I have
defined such a function. I've seen this work with other compilers. I've
tried
std::ostream& operator<<(std::ostream&os, const
std::pair<std::string,std::string>&x){ .... }
but that does not work either.
Can anyone tell me what I am doing wrong?
Thanks,
Siegfried
template <typename K, typename V>
inline std::ostream& operator<<(std::ostream& os, const std::pair<K,V>& x)
{
return os << "[" << x.first << ","<< x.second << "]";
}
std::map<std::string,std::string> m;
std::string hello="hello", world="world";
m[hello]=world;
std::copy(m.begin(),m.end(),
std::ostream_iterator<std::pair<std::string,std::string> >(std::cout));
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]