【发布时间】:2014-05-15 14:22:56
【问题描述】:
我有以下 C++ 代码
char* locale = setlocale(LC_ALL, "German"); // Get the CRT's current locale.
std::locale lollocale(locale);
setlocale(LC_ALL, locale); // Restore the CRT.
wcout.imbue(lollocale); // Now set the std::wcout to have the locale that we got from the CRT.
COORD cur = { 0, 0 };
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), cur);
wcout << L"Enemy " << this->enemyStrengthLeft << L"/" << this->enemyStrength << endl;
wcout << L"◄";
for (int i = 0; i < 20; i++) {
if (i % 2 == 0)
wcout << L"■";
else
wcout << L" ";
}
wcout << L"►" << endl;
当我执行它时,unicode字符不在cmd窗口中,我该如何解决?
编辑
我使用 Lucida Console 作为字体。
编辑 2
如果有帮助,我正在 Windows 7 Enterprise SP1 64 位下运行 Visual Studio 2013 Express for Desktop
【问题讨论】:
-
您的控制台窗口是否使用 TrueType 字体?
-
哦,对了,我要输入字体了。
-
这看起来像 Windows,在这种情况下,它需要
_setmode(_fileno(stdout), _O_WTEXT);才能将宽字符串发送到标准输出。 -
字符不显示是什么情况?它们是被遗漏、被替换,还是整个输出流在第一个 unicode 字符之后“停止”?
-
@Cubbi 是的,它是 Windows,但是我需要哪些头文件来解决你的“技巧”?