可以修改前景色(字体颜色)和背景色。
示例代码如下:
#include <iostream>
#include <Windows.h> //需要引用Windows.h
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
for(int i=255;i>=0;i--)
{
SetConsoleTextAttribute(hConsole, i);
cout<<"what color is this?"<<endl;
}
cin.get();
return 0;
}
效果如图所示: