Well, I hate to break it to you, but those are the two easiest ways of doing the colors. windows method is fairly easy:
SetConsoleTextAttribute(HANDLE handle, WORD color);
Parameter 1: HANDLE handle -
This is a HANDLE to the window's output buffer (that does sound confusing, doesn't it?). To make this simple, make a global variable like so:
Code:
HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
Now you've got the handle to the output so you can manipulate the text.
Parameter 2:
This parameter is the foreground/background color of the text. The colors are as follows:
Code:
FOREGROUND_RED // A dark red for the text
FOREGROUND_GREEN // A dark green
FOREGROUND_BLUE // A dark blue
FOREGROUND_INTENSITY // Makes the text colors brighter (so dark red would become red)
BACKGROUND_RED // A dark red for the text background
BACKGROUND_GREEN
BACKGROUND_BLUE
BACKGROUND_INTENSITY // Brightens the text background color
Those are very basic colors. You can combine them to make more. Like, if you wanted yellow text on a blue background, here would be the code:
Code:
SetConsoleTextAttribute(stdOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
Finally, here's my last example:
Code:
#include <iostream.h>
#include <windows.h>
// The HANDLE
HANDLE stdOut = GetStdHandle(STD_OUTPUT_HANDLE);
int main()
{
// Make red text
SetConsoleTextAttribute(stdOut, FOREGROUND_RED | FOREGROUND_INTENSITY);
cout << "Red text!\n";
return 0;
}
I hope that helps a little. Just ask if you need clarification.
Brendan