In a Windows console, use
SetConsoleTextAttribute()
In a
true DOS terminal, not a Win32 DOS-style console (these usually aren't supported on modern compilers), use textcolor and textbackground.
These aren't especially well-document so here it is:
Quote:
#include <conio.h>
void textcolor(int newcolor);
void textbackground(int newcolor);
newcolor can take one of the following constant values:
BLACK 0
BLUE 1
GREEN 2
CYAN 3
RED 4
MAGENTA 5
BROWN 6
LIGHTGRAY 7
The following are also valid, but may not be supported on some machines and will be displayed as their darker equivalents above:
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15
You can add BLINK to the newcolor for textcolor() to make it blink:
BLINK 128
e.g. textcolor(CYAN+BLINK);
textcolor and textbackground will only affect functions that use direct video output, such as cprintf. printf does not. I strongly doubt that iostream functions use DVO.
|
In both these cases, just call it before writing the coloured text.
To change the entire screen, a quick and easy way is to call the function/s followed by system("cls");
The final option is directly modifying the display's memory space, but I doubt this is 21st-century compatible, particularly in a multithreaded OS with terminal emulation. Likelihood is that you'll be using the first one.