如何在 Turbo C ++ 中书写彩色文字?也就是说,如何使用不同的颜色编写不同的文本,并且还有不同的背景颜色?
例如像这样...
textcolor(2);
cprintf("\n\t Hello World");
但我想为" Hello World"设置背景颜色。文字,也。。
答案 0 :(得分:0)
您可以使用textbackground
功能为文字背景着色,并使用textcolor
功能为文字着色。
在使用这些函数之前,请包含<stdio.h>
头文件!
要以不同方式为每个文字着色,您必须先为彼此设置textbackground
和textcolor
,然后使用cprintf
函数。
请注意以下示例:
#include<stdio.h>
#include<conio.h>
void main()
{
//full screen window w: 80, h: 50
window(1,1,80,50);
textbackground(0);//black color
clrscr();
textcolor(15); //white color
gotoxy(1,1); cprintf("WINDOW-1");
//window 2
window(10,10,40,20);
textbackground(1); //blue color
clrscr();
textcolor(15); //white color
gotoxy(1,1); cprintf("WINDOW-2");
//pause screen
getch();
}