如何更改文本和背景颜色? [英] How to change text and background color?

查看:174
本文介绍了如何更改文本和背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让每个字符都是不同的颜色。



例如,

 code> cout<< Hello world<< endl 




  • H 会是红色

  • e 会是蓝色的

  • l 会是橙色的
    等。 / li>


我知道这可以做,我只是不知道它的代码。



,我想将背景颜色更改为白色。我该怎么做?

解决方案

没有(标准)跨平台的方法来做到这一点。在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.

这篇关于如何更改文本和背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆