首页
软件
文章
留言
关于
【C++】控制台更改输出的颜色-文章-bci9

【C++】控制台更改输出的颜色

 [标签]  C++  函数
 2022-07-04
头文件:
#include<Windows.h>
函数: SetConsoleTextAttribute(); 使用: SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),A ); (第一个参数是要控制的窗口,必填,一般是本窗口) A:显示的颜色颜色对照如下: 亮红: FOREGROUND_INTENSITY|FOREGROUND_RED 暗红: FOREGROUND_RED 亮绿: FOREGROUND_INTENSITY|FOREGROUND_GREEN 暗绿: FOREGROUND_GREEN 亮蓝: FOREGROUND_INTENSITY|FOREGROUND_BLUE 暗蓝: FOREGROUND_BLUE  默认(暗白): FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE 亮白: FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE  灰色: FOREGROUND_INTENSITY 例子:
#include<iostream>
#include<Windows.h>
using namespace std;
int main(){
	SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED);//亮红 
	cout << "a" << endl;
	SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);//暗红 
	cout << "a" << endl;
	SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN);//亮绿 
	cout << "a" << endl;
	SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN);//暗绿 
	cout << "a" << endl;
	SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_BLUE);//亮蓝 
	cout << "a" << endl;
	SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE);//暗蓝
	cout << "a" << endl;
	SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);//默认(暗白) 
	cout << "a" << endl;
	SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);//亮白 
	cout << "a" << endl;
	SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);//灰
	cout << "a" << endl;
}
结果:
©bci9 版权所有

联系站长 [email protected]

bci9公众号