Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to print Colored text in C++

  • Difficulty Level : Easy
  • 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:

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for the language and STL. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
#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
Recommended Articles
Page :

Start Your Coding Journey Now!