0

How can I write colored text in Turbo C++? That is, how can I write different text with different colors and also have different Background colors?

For example like this...

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

But I want to set a background color for the "Hello World" text, also.

CLICK Too See Image..

hardillb
  • 54,545
  • 11
  • 67
  • 105
Hirad
  • 17
  • 1
  • 6

1 Answers1

0

You can use of textbackground function for coloring background of text and use of textcolor function for coloring the text.

before using of these functions, include <stdio.h> header file!

for coloring every text variously, you must first set textbackground and textcolor for each other, then use of cprintf function.

Attention bellow example:

#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();
}