• <bdo id='ptUAT'></bdo><ul id='ptUAT'></ul>

      <small id='ptUAT'></small><noframes id='ptUAT'>

      <legend id='ptUAT'><style id='ptUAT'><dir id='ptUAT'><q id='ptUAT'></q></dir></style></legend>
      <i id='ptUAT'><tr id='ptUAT'><dt id='ptUAT'><q id='ptUAT'><span id='ptUAT'><b id='ptUAT'><form id='ptUAT'><ins id='ptUAT'></ins><ul id='ptUAT'></ul><sub id='ptUAT'></sub></form><legend id='ptUAT'></legend><bdo id='ptUAT'><pre id='ptUAT'><center id='ptUAT'></center></pre></bdo></b><th id='ptUAT'></th></span></q></dt></tr></i><div id='ptUAT'><tfoot id='ptUAT'></tfoot><dl id='ptUAT'><fieldset id='ptUAT'></fieldset></dl></div>
        <tfoot id='ptUAT'></tfoot>

        在 Windows 中使用 C++ 将 Unicode 输出到控制台

        Output Unicode to console Using C++, in Windows(在 Windows 中使用 C++ 将 Unicode 输出到控制台)

          <tbody id='4yWzH'></tbody>
      1. <tfoot id='4yWzH'></tfoot>

        <small id='4yWzH'></small><noframes id='4yWzH'>

                • <bdo id='4yWzH'></bdo><ul id='4yWzH'></ul>
                • <i id='4yWzH'><tr id='4yWzH'><dt id='4yWzH'><q id='4yWzH'><span id='4yWzH'><b id='4yWzH'><form id='4yWzH'><ins id='4yWzH'></ins><ul id='4yWzH'></ul><sub id='4yWzH'></sub></form><legend id='4yWzH'></legend><bdo id='4yWzH'><pre id='4yWzH'><center id='4yWzH'></center></pre></bdo></b><th id='4yWzH'></th></span></q></dt></tr></i><div id='4yWzH'><tfoot id='4yWzH'></tfoot><dl id='4yWzH'><fieldset id='4yWzH'></fieldset></dl></div>
                  <legend id='4yWzH'><style id='4yWzH'><dir id='4yWzH'><q id='4yWzH'></q></dir></style></legend>

                  本文介绍了在 Windows 中使用 C++ 将 Unicode 输出到控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我仍在学习 C++,所以请忍受我和我草率的代码.我使用的编译器是 Dev C++.我希望能够使用 cout 将 Unicode 字符输出到控制台.每当我尝试以下操作时:

                  I'm still learning C++, so bear with me and my sloppy code. The compiler I use is Dev C++. I want to be able to output Unicode characters to the Console using cout. Whenver i try things like:

                  #include <iostream>
                  
                  int main()
                  {
                      std::cout << "Hello World!
                  ";
                      std::cout << "Blah blah blah some gibberish unicode: 
                  ";
                      system("PAUSE");
                      return 0;
                  }
                  

                  它会向控制台输出奇怪的字符,例如 A■Gg.为什么会这样,我如何才能显示 ?或者这在 Windows 上是不可能的?

                  It outputs strange characters to the console, like A■Gg. Why does it do that, and how can I get to to display ? Or is this not possible with Windows?

                  推荐答案

                  std::wcout 怎么样?

                  #include <iostream>
                  
                  int main() {
                      std::wcout << L"Hello World!" << std::endl;
                      return 0;
                  }
                  

                  这是标准的宽字符输出流.

                  This is the standard wide-characters output stream.

                  不过,正如 Adrian 指出的那样,这并没有解决 cmd 的事实,默认情况下,它不处理 Unicode 输出.这可以通过手动配置控制台来解决,如 Adrian 的回答中所述:

                  Still, as Adrian pointed out, this doesn't address the fact cmd, by default, doesn't handle Unicode outputs. This can be addressed by manually configuring the console, like described in Adrian's answer:

                  • /u参数开始cmd
                  • 调用chcp 65001改变输出格式;
                  • 并在控制台中设置 unicode 字体(如 Lucida Console Unicode).
                  • Starting cmd with the /u argument;
                  • Calling chcp 65001 to change the output format;
                  • And setting a unicode font in the console (like Lucida Console Unicode).

                  你也可以尝试使用_setmode(_fileno(stdout), _O_U16TEXT);,这需要fcntl.hio.h(如此答案中所述,以及记录在这篇博文).

                  You can also try to use _setmode(_fileno(stdout), _O_U16TEXT);, which require fcntl.h and io.h (as described in this answer, and documented in this blog post).

                  这篇关于在 Windows 中使用 C++ 将 Unicode 输出到控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)
                      • <bdo id='XSr3Y'></bdo><ul id='XSr3Y'></ul>
                        <i id='XSr3Y'><tr id='XSr3Y'><dt id='XSr3Y'><q id='XSr3Y'><span id='XSr3Y'><b id='XSr3Y'><form id='XSr3Y'><ins id='XSr3Y'></ins><ul id='XSr3Y'></ul><sub id='XSr3Y'></sub></form><legend id='XSr3Y'></legend><bdo id='XSr3Y'><pre id='XSr3Y'><center id='XSr3Y'></center></pre></bdo></b><th id='XSr3Y'></th></span></q></dt></tr></i><div id='XSr3Y'><tfoot id='XSr3Y'></tfoot><dl id='XSr3Y'><fieldset id='XSr3Y'></fieldset></dl></div>

                          <tbody id='XSr3Y'></tbody>

                      • <legend id='XSr3Y'><style id='XSr3Y'><dir id='XSr3Y'><q id='XSr3Y'></q></dir></style></legend><tfoot id='XSr3Y'></tfoot>
                        • <small id='XSr3Y'></small><noframes id='XSr3Y'>