Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to print a wstring/wchar_t in xcode to the console but unfortunatelly it only works with basic chars (i think ascii) chars, everything else gets displayed in numbers, for instance 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 about 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!

like image 338
moka Avatar asked Oct 14 '10 17:10

moka


1 Answers

i had a sinilar problem but with wostream/wofstream. Googled it and this was the 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;
}
like image 99
engf-010 Avatar answered Nov 07 '22 11:11

engf-010