#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
enum Color
{
black,blue,green,lakeBlue,red,purple,yellow,white,gray,
lightBlue,lightGreen,lightSimpleGreen,lightRed,lightPurple,
lightYellow,brightWhite
};
void setColor(enum Color x)
{
if(x>=0 && x<=15)//参数在0-15的范围颜色
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x); //只有一个参数,改变字体颜色
else//默认的颜色白色
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}
void setTexColor(char * str,enum Color c){
setColor(c);
printf("%s\n", str);
setColor(white);
}
int main(){
setTexColor("Text test..",green);
return 0;
}
原文地址:https://www.cnblogs.com/NULL-ROOT/p/9458903.html
时间: 2024-10-08 22:26:39