Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

How to print Colored text in C++

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 idColorColor idColor
1Blue9Light Blue
2Green0Black
3AquaALight Green
4RedBLight Aqua
5PurpleCLight Red
6YellowDLight Purple
7WhiteELight Yellow
8GrayFBright White

Below is the illustration of Text coloring in C++:

Program 1:




// C++ program to illustrate coloring
#include <iostream>
#include <windows.h>
using namespace std;
  
// Driver Code
int main()
{
    // 0 for background Color(Black)
    // A for text color(Green)
    system("Color 0A");
  
    // Print any message
    cout << "Geeks For Geeks!";
    return 0;
}

Output:

Program 2:




// C++ program to illustrate coloring
#include <iostream>
#include <stdlib.h>
using namespace std;
  
// Driver Code
int main()
{
    // Print any message
    cout << "Geeks For Geeks!";
  
    // We can print the statement first
    // and then changed the color
  
    // E for background Color(Light Yellow)
    // 4 for text color(Red)
    system("Color E4");
  
    return 0;
}

Output:

Program 3:




// C++ program to illustrate coloring
#include <iostream>
#include <stdlib.h>
using namespace std;
  
// Driver Code
int main()
{
    // B for background Color(Light Aqua)
    // 5 for text color(Purple)
    system("Color B5");
    cout << "Geeks";
  
    // 1 for background Color(Blue)
    // 6 for text color(Yellow)
    system("Color 16");
    cout << " For ";
  
    // D for background Color(Light Purple)
    // E for text color(Light Yellow)
    system("Color DE");
    cout << "Geeks";
  
    return 0;
}

Output:


My Personal Notes arrow_drop_up
Last Updated : 01 Jun, 2020
Like Article
Save Article
Similar Reads