【问题标题】:How to change the color of text to ANY color in C++如何在 C++ 中将文本的颜色更改为任何颜色
【发布时间】:2015-10-29 16:05:06
【问题描述】:

所以我需要将文本的颜色更改为,粉红色作为前景,黑色作为背景。我搜索了谷歌,但找不到任何说明如何将文本颜色更改为粉红色(或除蓝色/红色/绿色等之外的任何其他颜色)的内容。我知道

system("Color *back**fore*")

但那没有粉红色。那么有人可以帮助我吗?谢谢

【问题讨论】:

标签: c++


【解决方案1】:

我只能回答基于 linux 的终端。

#include <iostream>

using std::cout;
using std::endl;

int main(){

  char pinkish[] = { 0x1b, '[', '3', '8',';','5',';','2','1','2','m',0 };
  char normal[] = { 0x1b, '[', '0', ';', '3', '9', 'm', 0 };

  cout << pinkish << "Hello" << normal << endl;

}

使用 ANSI 颜色代码,向下滚动到 256 位颜色表。

{ 0x1b, '[', '3', '8',';','5',';','2','1','2','m',0 };

前景色:ESC[38;5;

背景颜色:ESC[48;5;

256位颜色值:212

终端字符(我猜):m

希望这会有所帮助,研究它很有趣。那里有很多很好的信息 - 很多,但希望我总结为您所要求的。

几个参考:

Using-ANSI-Color-Codes-to-Colorize-Your-Bash-Prompt-on-Linux

ansi-color-specific-rgb-sequence-bash

color for text

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-20
    • 1970-01-01
    • 1970-01-01
    • 2023-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-19
    相关资源
    最近更新 更多