代码解释 : 使用GetStdHandle获取标准输出的句柄,并调用SetConsoleTextAttribute设置其颜色。
#include <cstdio>
#include "Windows.h"
int main(int argc, char* argv[])
{
printf("这是默认\n");
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
printf("这是红色\n");
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY);
printf("这是灰色\n");
SetConsoleTextAttribute(handle, 0x0f);
printf("这是全部高亮\n");
SetConsoleTextAttribute(handle, 0x07);
printf("这是全部正常\n");
return 0;
}
网友评论