Snippet
#include <stdlib.h>
#include <windows.h>
#include <iostream>
using namespace std;
enum Color { DBLUE=1,GREEN,GREY,DRED,DPURP,BROWN,LGREY,DGREY,BLUE,LIMEG,TEAL,
RED,PURPLE,YELLOW,WHITE,B_B };
/* These are the first 16 colors anyways. You test the other hundreds yourself.
After 15 they are all combos of different color text/backgrounds. */
bool quit;
void col(unsigned short color)
{
HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hcon,color);
}
istream &operator>> ( istream &in, Color &c )
{
int tint;
cin >> tint;
if (tint==-1) quit=true;
c=(Color)tint;
}
int main()
{
do {
col(7); // Defaults color for each round.
cout << "Enter a color code, or -1 to quit... ";
Color y;
cin >> y; // Notice that >> is defined above for Color types.
col(y); // Sets output color to y.
if (!quit) cout << "Color: " << (int)y << endl;
} while (!quit);
return 0;
}
Copy & Paste
|