views:

14

answers:

1
wstring ws(L"Press 'q' to end.");
wcout << ws;

error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::wstring' (or there is no acceptable conversion)

This is in a VC++ 2005 Win32 console app, created with default settings... which I think means UNICODE is on? I only just found out cout doesn't seem to support wstring, which seems a bit ugly - is that true? This app interacts with libraries which return wstrings and it might as well be Unicode, is there some project setting I need to change?

A: 

Try

wstring ws(L"Press 'q' to end."); 
wcout << ws.c_str(); 

BTW: wchar != wstring

graham.reeds
You're saying STL can't cope with its own string types?
John
A lot of the time it can't. There's odd holes for various bits all through the spec. Most have been fixed by vendors over the years (similar to hash_maps inclusion) and officially as part of the 0x update.
graham.reeds
who said wstring == wchar? wstring is a container for wchar though.
John
You said it yourself. wstring is a container. How (or why) should a container know what to do with what it is containing when passed to an iostream?
graham.reeds
It must be an error in the STL implementation of VC++ 2005. There is definitely an overload of `operator<<` taking `wostream` and `wstring` defined in the standard.
Philipp
@graham.reeds ... basic_string is the core string type in C++. If standard IO methods don't work with standard strings, you don't see a problem with that?
John
I didn't say that, however there are several holes in the original 98 spec that didn't have strings as parameters forcing you to use C-style null terminated strings.
graham.reeds
One more reason to avoid wchar on windows. See also: http://stackoverflow.com/questions/1049947/should-utf-16-be-considered-harmful
Pavel Radzivilovsky