M
Marcus Kwok
glen said:Hi. I'm using GCC 4.1.1, which I mention since I don't know
if this is a compiler issue, or me not understanding some
subtlety in the standard.
The code below compiles fine under vc++, but I'm having trouble
using gcc. It's just a templated container output.
/**
outputs elements of a vector in the form '{el1,el2...elEnd}'
*/
template<typename C>
std:stream& operator<< (std:stream& op, const C& cpi )
{
typename C::const_iterator start( cpi.begin() ); typename
C::const_iterator end( --(cpi.end() )); typename C::const_iterator iter;
op << "{";
for (iter=start;iter!=end; ++iter){
op<<*iter<<",";
}
op<<*iter<<"}";
return op;
};
The offending lines are the
op<<"{";
and
op<<"}";
apparently it doesn't know what to do with a simple string, but it can
handle the template argument...
So am I on topic here, and if so can someone please give me a little
insight? I appreciate any assistance that can be given. Searched the web
but was unable to find anything that helped (I also posted to a g++ group).
AFAIK operator<< for a const char* should be available. Since it's only
a single character, maybe you could try
op << '{';
instead.
Another is to double-check that you have all the necessary #includes.
Maybe the Standard Library of VC++ implicitly includes something that
gcc does not. Also, make sure you are using g++ instead of gcc.