Anyone knows how to write something in colors in console applications?
For example, how do I write "Hello" in red?
Printable View
Anyone knows how to write something in colors in console applications?
For example, how do I write "Hello" in red?
If you're using Borland, try this:
If you're using Visual C++, try this:Code:#include <conio.h>
#include <stdio.h>
int main()
{
textcolor(15);
printf("Hello World!\n");
return 0;
}
Code:#include <windows.h>
#include <stdio.h>
int main()
{
// Set color to yellow
SetConsoleTextAttribute(GetStdHandle(STD_OUT), 14);
printf("Hello World!\n");
return 0;
}
Here is some more info for the SetConsoleTextAttribute second parameter
Quote:
wAttributes
Specifies the foreground and background color attributes. Any combination of the following values can be specified: FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY, BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_RED, and BACKGROUND_INTENSITY. For example, the following combination of values produces white text on a black background:
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE