How to print Colored text in C++
Last Updated :
01 Jun, 2020
In C++ programming, the background of the output screen is black and text color is in white color. We can color both the background and text color in the output screen in the following ways.
Header File:
#include <windows.h>
or
#include <stdlib.h>
Syntax:
system("Color XY")
In the above command to change the background color change the value X of the above syntax to the corresponding color you want and to change the text color change the value Y of the above syntax to the corresponding color you want.
Below is the table for allow color in C++:
Color id |
Color |
Color id |
Color |
1 |
Blue |
9 |
Light Blue |
2 |
Green |
0 |
Black |
3 |
Aqua |
A |
Light Green |
4 |
Red |
B |
Light Aqua |
5 |
Purple |
C |
Light Red |
6 |
Yellow |
D |
Light Purple |
7 |
White |
E |
Light Yellow |
8 |
Gray |
F |
Bright White |
Below is the illustration of Text coloring in C++:
Program 1:
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
system ( "Color 0A" );
cout << "Geeks For Geeks!" ;
return 0;
}
|
Output:
Program 2:
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
cout << "Geeks For Geeks!" ;
system ( "Color E4" );
return 0;
}
|
Output:
Program 3:
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
system ( "Color B5" );
cout << "Geeks" ;
system ( "Color 16" );
cout << " For " ;
system ( "Color DE" );
cout << "Geeks" ;
return 0;
}
|
Output:
Share your thoughts in the comments
Please Login to comment...