.

Thursday 22 January 2015

change text color of c/c++ console applications

Changing background or text of console in c++ is not a very major task. One can do it easily by doing some really good efforts . This tutorial is all about changing the colors in c++ which helps to look application similar like a desktop.

Step 1 -

Make header file for color as - Color.h and write the following code inside it.


#define RED "\x1b[31m"
#define GREEN "\x1b[32m"
#define YELLOW "\x1b[33m"
#define BLUE "\x1b[34m"
#define MAGENTA "\x1b[35m"
#define CYAN "\x1b[36m"
#define BRIGHT "\x1b[1m"
#define RESET "\x1b[0m"

step 2 -

Calling these colors with cout statement to change the text as per wish.




include your header file in the program as

#include "Color.h"

..
..

you can use red color of text by writing cout statement as ..

cout<<RED<<"enter the string"<<RESET;

blue as

cout<<BLUE<<"enter the string"<<RESET;

yellow as

cout<<YELLOW<<"enter the string"<<RESET;

now it will always print the text in a desired form.

No comments:

Post a Comment