修改cmd控制台字体颜色,附C++代码

写程序修改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;
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值