Gold mine of Visual C++ tricks!
How to Set Console Text Color?
![]()
Getting bored with the black and white console? Did you ever wish to change the text or background color of console?

Image Courtesy – reginadowntown.
![]()
Yes! You can use the api – SetConsoleTextAttribute(). See the code snippet below.
// Set text color as Yellow with white background.
SetConsoleTextAttribute(
GetStdHandle( STD_OUTPUT_HANDLE ),
FOREGROUND_INTENSITY | // Set Text color
FOREGROUND_RED | FOREGROUND_GREEN | // Text color as Yellow.
BACKGROUND_INTENSITY | // Set Background color
BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE ); // White Bg.
![]()
Please note that you can mix red/green/blue constants to make new colors. Have fun.
![]()
Targeted Audience – Beginners.
Hi. I tried it and it worked. Thanks a lot. Pretty bored of black and white… yeah.
Hi Josh,
Happy to know that you enjoyed it!
Keep watching!
Regards,
Jijo