Xcode std :: wcout with wchar_t or std :: wstring!

I am trying to print wstring / wchar_t in xcode on the console, but unfortunately it only works with basic characters (I think ascii), everything else is displayed in numbers, like the following:

std::cout << "äöüu"<< std::endl; std::wcout << L"äöüu" << std::endl; 

while the cout version prints "äöüu", as expected, I get the following when using wchar_t:

\ 344 \ 366 \ 374u

any ideas on how to fix this? I am using xcode 3.2.2 64 bit and gcc 4.2 with file encoding set to Unicode (UTF-8)

Thanks!

+6
c ++ string xcode character-encoding
source share
2 answers

I had a strong problem, but with wostream / wofstream. In Googled it is, and it was anser:

 tc_ofstream ofs; if (sizeof(TCHAR) == sizeof(wchar_t)) { //codecvt_utf16<TCHAR> utf16; cannot make use of non-dynamic value locale loc ( locale::classic() ,new codecvt_utf16<TCHAR> ); ofs.imbue( loc ); ofs.open( _T(".\\test.txt") ,tc_ios::binary ); TCHAR BOM = 0xFEFF; ofs << BOM; ofs << _T("UNICODE") << endl; } else { ofs.open( _T(".\\test.txt") ,tc_ios::binary ); ofs << _T("NON-UNICODE") << endl; } 
+1
source share

If you use wxWidgets, wxString handles this for you automatically using wxConvCurrent.

0
source share

All Articles