且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何更改文本和背景颜色?

更新时间:2023-01-27 20:35:42

没有(标准)跨平台的方法来做到这一点。在Windows上,尝试使用 conio.h
它有:

  textcolor(); // and 
textbackground();

功能。



/ p>

  textcolor(RED) 
cprintf(H);
textcolor(BLUE);
cprintf(e);
//等等。


I want every character to be a different color.

for example,

cout << "Hello world" << endl;

  • H would be red
  • e would be blue
  • l would be orange and so on.

I know this can be done, I just don't know the code for it.

and I want to change the background color to white. How would I do that?

There is no (standard) cross-platform way to do this. On windows, try using conio.h. It has the:

textcolor(); // and
textbackground();

functions.

For example:

textcolor(RED);
cprintf("H");
textcolor(BLUE);
cprintf("e");
// and so on.