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

  • <tfoot id='KabXl'></tfoot>

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

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

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

      1. 在 Windows 中使用 C++ 的颜色控制台输出

        时间:2023-05-23

        <small id='2Gqtq'></small><noframes id='2Gqtq'>

            <tbody id='2Gqtq'></tbody>

            1. <legend id='2Gqtq'><style id='2Gqtq'><dir id='2Gqtq'><q id='2Gqtq'></q></dir></style></legend>
                  <bdo id='2Gqtq'></bdo><ul id='2Gqtq'></ul>

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

                  <tfoot id='2Gqtq'></tfoot>
                  本文介绍了在 Windows 中使用 C++ 的颜色控制台输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  有没有办法将彩色文本输出到控制台?我使用的是 Visual Studio 2010,只需要代码即可在 Windows 中工作.

                  Is there a way to output colored text to the console? I am using Visual Studio 2010, and only need the code to work in Windows.

                  除了 windows COLOR 命令之外,我一直没有找到任何东西,但这改变了整个屏幕的颜色,我正在寻找只会改变我希望输出的部分的东西.我已经看到它在托管 C++ 中完成

                  I have been unsuccessful in finding anything except the windows COLOR command, but that changed the color for the entire screen, and I am looking for something that will change only the part I wish to output. I've seen it done in Managed C++

                  例如,

                  {color red}
                  cout << "Hello ";
                  {color blue}
                  cout << "world
                  ";
                  

                  将产生红色和蓝色的Hello world".

                  would yield "Hello world" in red and blue.

                  推荐答案

                  我从 此处:

                  // color your text in Windows console mode
                  // colors are 0=black 1=blue 2=green and so on to 15=white
                  // colorattribute = foreground + background * 16
                  // to get red text on yellow use 4 + 14*16 = 228
                  // light red on yellow would be 12 + 14*16 = 236
                  // a Dev-C++ tested console application by vegaseat 07nov2004
                  
                  #include <iostream>
                  #include <windows.h> // WinApi header
                  
                  using namespace std; // std::cout, std::cin
                  
                  int main()
                  {
                  HANDLE hConsole;
                  int k;
                  
                  hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
                  
                  // you can loop k higher to see more color choices
                  for(k = 1; k < 255; k++)
                  {
                  // pick the colorattribute k you want
                  SetConsoleTextAttribute(hConsole, k);
                  cout << k << " I want to be nice today!" << endl;
                  }
                  
                  cin.get(); // wait
                  return 0;
                  }
                  

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

                  上一篇:如何在依赖静态库中链接 Boost 下一篇:在 Visual Studio 2010 中将输出消息写入“输出窗口

                  相关文章

                  最新文章

                    <legend id='q2Yoc'><style id='q2Yoc'><dir id='q2Yoc'><q id='q2Yoc'></q></dir></style></legend>
                  1. <small id='q2Yoc'></small><noframes id='q2Yoc'>

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