5

我知道正确显示本地化字符的简单方法Cmd.exe。但是我该怎么做Powershell.exe呢?

#include<iostream>
#include<windows.h>

using namespace std;
int main()
{
    SetConsoleCP(GetACP());
    SetConsoleOutputCP(GetACP());

    // valid output in cmd.exe, 
    // but invalid output in powershell.exe
    cout << "Привет мир (1)!" << endl; 

    // invalid output in both variants: cmd.exe, 
    // and powershell.exe
    wcout << L"Привет мир (2)!" << endl; 

    return 0;
}
4

2 回答 2

0

输出是什么?你的字体支持那些字形吗?

也许以下链接可能有用(关于 cmd.exe):

http://www.watchingthenet.com/how-to-add-and-change-fonts-in-windows-command-prompt.html

您还可以尝试将输出从 powershell 重定向到文件并检查。如果文件正确,则您的控制台字体不支持您的字符。

还有一个来自ms的博客,展示了如何自定义字体(关于ps)

http://blogs.msdn.com/b/powershell/archive/2006/10/16/windows-powershell-font-customization.aspx

于 2012-11-06T13:36:09.497 回答
0

我认为这是在 Windows中启用正确处理的捷径。 wcout尝试将其作为第一行添加到您的main

_setmode(_fileno(stdout), _O_U16TEXT);

之后,wcout << L"Привет мир (2)!" << endl;它将像魅力一样独立于用户选择的当前语言环境和单字节编码(应该如此)。

于 2015-07-05T16:27:39.463 回答