写程序修改cmd窗口字体颜色
代号 | 颜色 |
---|---|
0 | 黑色 |
1 | 蓝色 |
2 | 绿色 |
3 | 浅绿色 |
4 | 红色 |
5 | 紫色 |
6 | 黄色 |
7 | 白色 |
8 | 灰色 |
9 | 淡蓝色 |
A/a | 淡绿色 |
B/b | 淡浅绿色 |
C/c | 淡红色 |
D/d | 淡紫色 |
E/e | 淡黄色 |
F/f | 亮白色 |
最上边的黑色和背景色重复了,然后颜色会因为不同的屏幕的呈现略有差异
#include <iostream>
#include<windows.h>
using namespace std;
/* C++ */
int main(int argc, char *argv[])
{
/* 设置字体颜色 务必记住#include<windows.h>*/
HANDLE outHandle=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(outHandle,0x00);
cout<<"黑色"<<endl;
SetConsoleTextAttribute(outHandle,0x01);
cout<<"蓝色"<<endl;
SetConsoleTextAttribute(outHandle,0x02);
cout<<"绿色"<<endl;
SetConsoleTextAttribute(outHandle,0x03);
cout<<"浅绿色"<<endl;
SetConsoleTextAttribute(outHandle,0x04);
cout<<"红色"<<endl;
SetConsoleTextAttribute(outHandle,0x05);
cout<<"紫色"<<endl;
SetConsoleTextAttribute(outHandle,0x06);
cout<<"黄色"<<endl;
SetConsoleTextAttribute(outHandle,0x07);
cout<<"白色"<<endl;
SetConsoleTextAttribute(outHandle,0x08);
cout<<"灰色"<<endl;
SetConsoleTextAttribute(outHandle,0x09);
cout<<"淡蓝色"<<endl;
SetConsoleTextAttribute(outHandle,0x0a);
cout<<"淡绿色"<<endl;
SetConsoleTextAttribute(outHandle,0x0b);
cout<<"淡浅绿色"<<endl;
SetConsoleTextAttribute(outHandle,0x0c);
cout<<"淡红色"<<endl;
SetConsoleTextAttribute(outHandle,0x0d);
cout<<"淡紫色"<<endl;
SetConsoleTextAttribute(outHandle,0x0e);
cout<<"淡黄色"<<endl;
SetConsoleTextAttribute(outHandle,0x0f);
cout<<"亮白色"<<endl;
return 0;
}