Boost logo

Boost Users :

From: Terje Slettebų (tslettebo_at_[hidden])
Date: 2003-07-27 12:16:50


>From: "Stefan Felkel" <Stefan.Felkel_at_[hidden]>

> I have problems compiling the following piece of code under Microsoft
Visual C++
> 6.0 with UNICODE defined. The compiler complains about a missing
operator<<.
> What can I do in order to get this programme compiled ?
>
>
> #include <iostream>
> #include <boost/lexical_cast.hpp>
>
> int main( int argc, char * argv [] )
> {
> std::wcout << boost::lexical_cast<std::wstring>( std::wstring( L"test" )
> ).c_str() << L"\n";
>
> return 0;
> }
>
>
> c:\programme\boost_1_30_0\boost\lexical_cast.hpp(148): error C2679: binary
'<<':
> no operator defined which takes a right-hand operand of type 'const
wstring' (or
> there is no acceptable conversion)
>
> c:\programme\boost_1_30_0\boost\lexical_cast.hpp(146): while compiling
> class-template member function 'bool
> boost::detail::lexical_stream<wstring,wstring>::operator <<(const wstring
&)'

MSVC 6.0 has no intrinsic wchar_t (it's a synonym for unsigned short), so it
treats wchar_t as unsigned short, in other words an integer, and the same
goes for std::wstring. In order to not break the use with other libraries
(like Boost Date/Time, which uses unsigned short), lexical_cast has wide
character support turned off when there's no intrinsic wchar_t. Therefore,
you can't use lexical_cast with wide characters/strings on MSVC 6. It works
on MSVC 7, though, which has an (optional) intrinsic wchar_t.

Regards,

Terje


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net