显示带重音的字符 C/C++?

huangapple go评论67阅读模式
英文:

Display accented characters C/C++?

问题

我使用MinGW 4.9.1编写了一个程序,其中使用了"é"或"à"的printf()函数,我使用了以下代码来显示这些字符,并且运行正常:

然而,当我使用MinGW 11.2编译相同的程序时,重音字符显示为"é" "Ã"。我尝试过使用setlocale(LC_ALL, "");,但也没有起作用。

是否有人有解决方案?

英文:

I wrote a program using printfs() of "é" or "à" compiling with MinGW 4.9.1, I was using
setlocale(LC_CTYPE, "fra");
to display these characters and it worked well

However when I compile the same program with MinGW 11.2 the accents are displayed this way : "é" "Ã"
I tried with setlocale(LC_ALL, ""); and it doesn't work either

Does anyone have a solution?

答案1

得分: 2

在Windows上,您必须显式设置utf-8,而不像Linux等其他平台:

std::setlocale(LC_ALL, ".utf8")

除非程序或用户选择,否则Windows会在其区域设置中使用代码页。执行此操作会在控制台中启用Windows对utf-8的支持。

英文:

On Windows, you must explicitly set utf-8 as opposed to other platforms like Linux:

std::setlocale(LC_ALL, ".utf8")

Windows assume code pages in its locale configuration unless the program or the user selects it. Doing this activates windows support for utf-8 in the console.

huangapple
  • 本文由 发表于 2023年6月19日 21:00:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76506898.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定