Feb 102009
Easy! call SetConsoleTextAttribute function with appropriate color codes as follows…
// 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
SetColor( FOREGROUND_BLUE );
cout << "Visit http://nibuthomas.wordpress.com"; <<; endl;
// This time change background color too
SetColor( FOREGROUND_BLUE|BACKGROUND_RED|BACKGROUND_INTENSITY)
cout << "Visit http://nibuthomas.wordpress.com" << endl;
return 0;
}
[...] How to change console application text color? « bits and bytes Easy! call SetConsoleTextAttribute function with appropriate color codes as follows… (tags: color c++ GUI consol) [...]
INvalid unless you state which compiler and where the prototype for SetConsoleTextAttribute(… is Does not work ‘as-is’ in MS Vis C++ 6
The header file to include will be windows.h