How to change console application text color?

Easy! call SetConsoleTextAttribute function with appropriate color codes as follows…

[sourcecode language=’cpp’]// A generic function call to set color for text being output
void SetColor( const int Color )
SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), Color );

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
// Only change foreground color
cout << "Visit"; <<; endl; // This time change background color too SetColor( FOREGROUND_BLUE|BACKGROUND_RED|BACKGROUND_INTENSITY) cout << "Visit" << endl; return 0; }[/sourcecode]

3 thoughts on “How to change console application text color?

  1. INvalid unless you state which compiler and where the prototype for SetConsoleTextAttribute(… is Does not work ‘as-is’ in MS Vis C++ 6

Appreciate your comments...