在 Turbo C++ 中为文本着色

Colorizing text in Turbo C++

如何在 Turbo C++ 中编写彩色文本?也就是说,我怎样才能用不同的颜色写不同的文字,也有不同的背景颜色?

比如像这样...

textcolor(2); 
cprintf("\n\t Hello World");

但我还想为 "Hello World" 文本设置背景颜色。

您可以使用 textbackground 函数为文本背景着色,并使用 textcolor 函数为文本着色。

在使用这些函数之前,包含<stdio.h>头文件!

要为每个文本着色不同,您必须先为彼此设置 textbackgroundtextcolor,然后使用 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();
}