1. <tfoot id='9QAEI'></tfoot>
    <i id='9QAEI'><tr id='9QAEI'><dt id='9QAEI'><q id='9QAEI'><span id='9QAEI'><b id='9QAEI'><form id='9QAEI'><ins id='9QAEI'></ins><ul id='9QAEI'></ul><sub id='9QAEI'></sub></form><legend id='9QAEI'></legend><bdo id='9QAEI'><pre id='9QAEI'><center id='9QAEI'></center></pre></bdo></b><th id='9QAEI'></th></span></q></dt></tr></i><div id='9QAEI'><tfoot id='9QAEI'></tfoot><dl id='9QAEI'><fieldset id='9QAEI'></fieldset></dl></div>

      <legend id='9QAEI'><style id='9QAEI'><dir id='9QAEI'><q id='9QAEI'></q></dir></style></legend>

      <small id='9QAEI'></small><noframes id='9QAEI'>

      • <bdo id='9QAEI'></bdo><ul id='9QAEI'></ul>

      如何更改 Windows 控制台应用程序中的文本或背景颜色

      时间:2023-07-01
      <legend id='3qTU4'><style id='3qTU4'><dir id='3qTU4'><q id='3qTU4'></q></dir></style></legend>

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

      <small id='3qTU4'></small><noframes id='3qTU4'>

            <tbody id='3qTU4'></tbody>
              • <bdo id='3qTU4'></bdo><ul id='3qTU4'></ul>
                <tfoot id='3qTU4'></tfoot>
                本文介绍了如何更改 Windows 控制台应用程序中的文本或背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                哪个 C++ 函数会更改文本或背景颜色(MS Visual Studio)?比如cout<<"This text";如何让"This text"变成红色.

                Which C++ function changes text or background color (MS Visual studio)? For example cout<<"This text"; how to make "This text" red color.

                推荐答案

                颜色不是 C++ 的东西,而是 终端 的属性.如果您的终端使用 ANSI(例如,任何 Linux 终端,或 DOS 或 Windows NT,如果您将 DEVICE=C:DOSansi.sys 添加到您的 config.sys,或以后的Windows如果你用cmd.exe/kansicon调用shell,那么你可以试试下面的噱头:

                Colour isn't a C++ thing, but a property of your terminal. If your terminal speaks ANSI (e.g. any Linux terminal, or DOS or Windows NT if you add DEVICE=C:DOSansi.sys to your config.sys, or later Windows if you call the shell with cmd.exe /kansicon), then you can try the following gimmick:

                #define ANSI_COLOR_RED     "x1b[31m"
                #define ANSI_COLOR_GREEN   "x1b[32m"
                #define ANSI_COLOR_YELLOW  "x1b[33m"
                #define ANSI_COLOR_BLUE    "x1b[34m"
                #define ANSI_COLOR_MAGENTA "x1b[35m"
                #define ANSI_COLOR_CYAN    "x1b[36m"
                
                #define ANSI_COLOR_BRIGHT  "x1b[1m"
                #define ANSI_COLOR_RESET   "x1b[0m"
                
                
                std::cout << ANSI_COLOR_RED "Hello World
                " ANSI_COLOR_RESET;
                

                维基百科有一个ANSI 转义序列列表.

                这篇关于如何更改 Windows 控制台应用程序中的文本或背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 C++ 中逐个字符地从文本文件中读取 下一篇:以二进制和文本方式打开文件的区别

                相关文章

                      <bdo id='owbJE'></bdo><ul id='owbJE'></ul>

                    <tfoot id='owbJE'></tfoot>
                    <i id='owbJE'><tr id='owbJE'><dt id='owbJE'><q id='owbJE'><span id='owbJE'><b id='owbJE'><form id='owbJE'><ins id='owbJE'></ins><ul id='owbJE'></ul><sub id='owbJE'></sub></form><legend id='owbJE'></legend><bdo id='owbJE'><pre id='owbJE'><center id='owbJE'></center></pre></bdo></b><th id='owbJE'></th></span></q></dt></tr></i><div id='owbJE'><tfoot id='owbJE'></tfoot><dl id='owbJE'><fieldset id='owbJE'></fieldset></dl></div>
                  1. <small id='owbJE'></small><noframes id='owbJE'>

                    <legend id='owbJE'><style id='owbJE'><dir id='owbJE'><q id='owbJE'></q></dir></style></legend>