That only works for command shells that support that, such as most of them in Linux and UNIX (if not /all/ of them). :P
For Windows, you would need to do the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#include <iostream>
#include <windows.h>
using namespace std;
//returns the current attributes
WORD GetConsoleTextAttribute (HANDLE hCon)
{
CONSOLE_SCREEN_BUFFER_INFO con_info;
GetConsoleScreenBufferInfo(hCon, &con_info);
return con_info.wAttributes;
}
int main (void)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
const int saved_colors = GetConsoleTextAttribute(hConsole);
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
cout << "This text should be blue" << endl;
SetConsoleTextAttribute(hConsole, saved_colors);
}
|
Windows is a pain. I'm not sure if it would be any easier with .NET if that is available...
Anyway, you can find the available attributes for Windows here:
http://msdn2.microsoft.com/en-us/library/ms682088(VS.85).aspx#_win32_character_attributes
(you can ignore the bit about DBCS, Double-Byte Character Sets, probably)
I hope this helps! ^_^
rpgfan
Edit: According to that Wikipedia article jsmith posted (thanks for that), you can do it in DOS-based versions of Windows (95, 98, ME and earlier) as long as ANSI.SYS is loaded. The same is true of NT-based versions. However, it wouldn't make your program very reliable if it wasn't loaded, would it? ^_^