Showing posts with label color. Show all posts
Showing posts with label color. Show all posts

Saturday, February 14, 2009

Console: Setting the text color (C++)

Introduction
When making console apps, be it just learning C++ or for a school project, you want your apps to appeal to the feature-hungry crowd.

One way you can increase the loveliness of your application is by easily setting the color your console font.

In all fairness, it's very easy. In order to change the color, we will need to use SetConsoleTextAttribute(), which is located in windows.h.

Code
enum Colors { blue = 1, green, cyan, red, purple, yellow, grey, dgrey, hblue, hgreen, hred, hpurple, hyellow, hwhite };

HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);

void Print(int color, std::string output)
{
SetConsoleTextAttribute( handle, color);
cout << output;
}


 

C++ Universe - The universe compromised of C++ and C#. Powered By Blogger © 2009.