简体   繁体   English

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

[英]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: 我试图在xcode中将wstring / wchar_t打印到控制台但不幸的是它只适用于基本字符(我认为是ascii)字符,其他所有内容都以数字显示,例如以下内容:

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: 虽然cout版本按预期打印“äöüu”但是在使用wchar_t时会得到以下内容:

\\344\\366\\374u \\ 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) 我使用xcode 3.2.2 64位和gcc 4.2,文件编码设置为Unicode(UTF-8)

Thanks! 谢谢!

i had a sinilar problem but with wostream/wofstream. 我有一个单纯的问题,但有wostream / wofstream。 Googled it and this was the anser: 谷歌搜索它,这是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;
}

如果你使用wxWidgets,wxString会使用wxConvCurrent自动处理这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM