Hello.
I've searched for an answer but couldn't find one.
How can I force my program in console to display the folowing in colors of my choice:
1) output text (cout)
2) background
Thanks..
Well one way to do it is use the
system();
function defined in <stdlib.h>.
It executes a command in the command processor.
To set the color you need to use the 'color' keyword.
The syntax is:
Where BG_BIT is the bit corresponding to the background color, and FG_BIT the text color.
The colors are as follows:
Background:
1 2 3 4 5 6 7 8 9 10
|
/*
0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
*/
|
Foreground:
1 2 3 4 5 6 7 8 9 10
|
/*
8 = Gray
9 = Light Blue
A = Light Green
B = Light Aqua
C = Light Red
D = Light Purple
E = Light Yellow
F = Bright White
*/
|
So to make a white background with red text use:
system("color 7c");
Note that sometimes the colors arn't exactly as described (in my opinion)
Last edited on
that looks like a cool library