views:

210

answers:

1

I tried [NSString stringWithUTF8String:(const char*)(myWString.c_str())] but that returns a single character string.

This is on the iPhone by the way, if that matters any :)

+4  A: 

wstring::c_str() returns a wchar_t*, not a char*. Try this:

[NSString stringWithCString:(const char*)myWString.c_str()
                   encoding:NSUnicodeStringEncoding]
Marcelo Cantos
The following code produces no output:wstring myString = L"hello world"; NSString* s = [NSString stringWithCString:(const char*)myString.c_str() encoding:NSUnicodeStringEncoding];NSLog(s);
Harald Maassen
Try `stringWithCharacters:length:` instead. I don't have a Mac in front of me, so I can't test it, sorry.
Marcelo Cantos