I just discovered you could use system ("color 2") to change the text color and background color of the command box and I was wondering If you could have the user input a number and have it change the color of the box. Appearently it needs to be a string literal but I dont want to have the user type something like "color 23" just 23.
This is my attempt to do this:
1 2 3 4 5 6
int main()
{
char x = '0';
cin >> x;
system ("color " + x);
}
Yeah, I forgot that you have to convert the string in a C string: system( ("color "+color).c_str() );
To use the Windows function, try this: SetConsoleTextAttribute ( GetStdHandle ( STD_OUTPUT_HANDLE ) , color );
'color' is a number made of two bytes, the higher is the background and the lower the foreground eg if color is 0x0C the result would be black background and red text. You can find some constants at http://msdn.microsoft.com/en-us/library/ms682088(VS.85).aspx
When you can avoid the 'system' function is better