英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论