#157 (with fix) error C2679: no operator .. with stlp_std::string

None
closed-fixed
None
5
2014-12-15
2012-11-18
No

vs2010 with STLPort.5.2.1 and Boost.1_52
XP SP3

error:
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'stlpd_std::string'

this happens with the files
ql\currency.cpp (26)
ql\errors.cpp : lines 53,56,58
ql\patterns\observable.hpp : line 140

The reason is that stlport doesn't give an implicit conversion from string to c_str() when needed (but I don't know what is the current standard on this specific point).

The fixes is just to provide the c_str() member.
We cannot use a str() member because it's not given with STLPort.

So here the fixes for the different files:
ql\currency.cpp : line 26
return out << c.code().c_str();

ql\errors.cpp : lines 53,56,58
std::ostringstream msg;
#ifdef QL_ERROR_FUNCTIONS
if (function != "(unknown)")
msg << function.c_str() << ": ";
#endif
#ifdef QL_ERROR_LINES
msg << "\n " << file.c_str() << "(" << line << "): \n";
#endif
msg << message.c_str();
return msg.str();

ql\patterns\observable.hpp : line 140
QL_ENSURE(successful,
"could not notify one or more observers: " << errMsg.c_str() );

Here is the full report for one file:
1>D:\Projs\Libraries\Public\QuantLib\QuantLib-Active\ql/patterns/observable.hpp(140): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'stlpd_std::string' (or there is no acceptable conversion)
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(297): could be 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::operator <<<char,stlpd_std::char_traits<char>>(stlpd_std::basic_ostream<_CharT,_Traits> &,char)' [found using argument-dependent lookup]
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(304): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::operator <<<stlpd_std::char_traits<char>>(stlpd_std::basic_ostream<_CharT,_Traits> &,char)' [found using argument-dependent lookup]
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(311): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::operator <<<stlpd_std::char_traits<char>>(stlpd_std::basic_ostream<_CharT,_Traits> &,signed char)' [found using argument-dependent lookup]
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(318): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::operator <<<stlpd_std::char_traits<char>>(stlpd_std::basic_ostream<_CharT,_Traits> &,unsigned char)' [found using argument-dependent lookup]
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(325): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::operator <<<char,stlpd_std::char_traits<char>>(stlpd_std::basic_ostream<_CharT,_Traits> &,const char *)' [found using argument-dependent lookup]
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(332): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::operator <<<stlpd_std::char_traits<char>>(stlpd_std::basic_ostream<_CharT,_Traits> &,const char *)' [found using argument-dependent lookup]
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(339): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::operator <<<stlpd_std::char_traits<char>>(stlpd_std::basic_ostream<_CharT,_Traits> &,const signed char *)' [found using argument-dependent lookup]
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(346): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::operator <<<stlpd_std::char_traits<char>>(stlpd_std::basic_ostream<_CharT,_Traits> &,const unsigned char *)' [found using argument-dependent lookup]
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(78): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(stlpd_std::basic_ostream<_CharT,_Traits> &(__cdecl *)(stlpd_std::basic_ostream<_CharT,_Traits> &))'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(79): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(stlpd_std::basic_ostream<_CharT,_Traits>::__ios_base_fn)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(80): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(stlpd_std::basic_ios<_CharT,_Traits> &(__cdecl *)(stlpd_std::basic_ios<_CharT,_Traits> &))'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(101): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(stlpd_std::basic_streambuf<_CharT,_Traits> *)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(104): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(unsigned char)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(106): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(short)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(107): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(unsigned short)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(108): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(int)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(115): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(size_t)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(117): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(long)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(118): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(unsigned long)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(120): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(__int64)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(121): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(unsigned __int64)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(123): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(float)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(124): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(double)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(126): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(long double)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(128): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(const void *)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> d:\Projs\Libraries\BSD\STLPort\STLport-Active\stlport\stl/_ostream.h(130): or 'stlpd_std::basic_ostream<_CharT,_Traits> &stlpd_std::basic_ostream<_CharT,_Traits>::operator <<(bool)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]
1> while trying to match the argument list '(stlpd_std::basic_ostream<_CharT,_Traits>, stlpd_std::string)'
1> with
1> [
1> _CharT=char,
1> _Traits=stlpd_std::char_traits<char>
1> ]

Discussion

  • I must add that probably this error comes with STLPort only
    The fix should be valid also without STLPort
    so I wouldn't surround the fixes with the condition:
    #ifdef _STLPORT_VERSION
    #endif

    By doing this the fixes would be like, of course:

    ql\currency.cpp : line 26
    #ifdef _STLPORT_VERSION
    return out << c.code().c_str();
    #else
    return out << c.code();
    #endif

     
  • Luigi Ballabio
    Luigi Ballabio
    2012-11-19

    Thanks for the report, but I'm a bit confused. A statement like "out << c.code()" isn't expected to trigger a conversion to C string; it just invokes operator << for std::string, which is defined by the standard. Do you have any idea why STLPort doesn't define it?

     
  • You're right
    "#include <string>"
    was forgotten

    I looked around
    http://stackoverflow.com/questions/8679473/error-c2679-binary-no-operator-found-which-takes-a-right-hand-operand-of

    The std::string operators are defined in the "<string>" header.
    The header "<string.h>" is for C-style string functions.

    On QuantLib 1.3 only three files need this fix:
    ql\patterns\observable.hpp
    ql\currency.cpp
    ql\errors.cpp
    and they all include ql\errors.hpp

    so my proposed fix is to add
    "#include <string>"
    in ql\errors.hpp

    Cheers,
    Marcello

    P.S. this Markdown formatting feature to type some code doesn't work here or I don't know how to do it, so I had to find a weird way to write "<string.h>" and similar stuff.. if you know how, svp let me know ;)

     
    Last edit: Marcello Pietrobon 2013-08-17
  • Luigi Ballabio
    Luigi Ballabio
    2013-09-10

    • status: open --> closed-fixed
    • assigned_to: Luigi Ballabio
    • Group: -->
     
  • Luigi Ballabio
    Luigi Ballabio
    2013-09-10

    Done in the git repository, thanks for the heads-up.