简体   繁体   English

更改C ++中的控制台颜色

[英]change the console color in c++

I have code blocks 12.11. 我有代码块12.11。 During a program I have changed colour of the console with this code: 在编写程序期间,我使用以下代码更改了控制台的颜色:

    setColor(8 , 15) ;

after this code the colour of the console has changed to grey, Even in other programs. 在此代码之后,控制台的颜色已变为灰色,即使在其他程序中也是如此。 Then I uninstalled code blocks and installed it again but again I have this problem. 然后我卸载了代码块,然后再次安装了它,但是再次出现了这个问题。 I think I have changed code blocks default .can anyone please help me. 我认为我已更改了默认的代码块。任何人都可以帮助我。 Thanks in advance. 提前致谢。

I guess that setColor() arguments are numbers that represent color constants: 我猜想setColor()参数是代表颜色常量的数字:

+--------------+-----+
| BLACK        | 0   |   
| BLUE         | 1   |   
| GREEN        | 2   |   
| CYAN         | 3   |   
| RED          | 4   |   
| MAGENTA      | 5   |   
| BROWN        | 6   |   
| LIGHTGREY    | 7   |   
| DARKGREY     | 8   |   
| LIGHTBLUE    | 9   |   
| LIGHTGREEN   | 10  |
| LIGHTCYAN    | 11  |
| LIGHTRED     | 12  |
| LIGHTMAGENTA | 13  |
| YELLOW       | 14  |
| WHITE        | 15  |
| BLINK        | 128 |
+--------------+-----+

You see that 8 is DARKGRAY and 15 is WHITE . 您会看到8DARKGRAY15WHITE So, if you want to set background color as black and the text color to white you will run: 因此,如果要将背景色设置为黑色,而将文本颜色设置为白色 ,则将运行:

setColor(0, 15);

If you are on Windows: 如果您使用的是Windows:

  1. Open a command-prompt 打开命令提示符
  2. Right-click the titlebar or press Alt + Space 右键单击标题栏或按Alt + 空格
  3. Select Defaults from the context-menu 从上下文菜单中选择默认值
  4. Set the properties you would like (colors on the Colors tab) 设置所需的属性(“ 颜色”选项卡上的颜色
  5. Click OK 点击确定

The method that Tapped-Out gave works because Windows 7 happens to have a bug where the Properties option modifies the default values instead of just for the current console, and it could be fixed at any time. Tapped-Out提供的方法之所以可行,是因为Windows 7碰巧有一个bug ,其中“ Properties”(属性)选项修改了默认值而不是仅修改当前控制台的默认值,并且可以随时对其进行修复。 source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM