根据C语言中各个色号的调用不同,本人直接整理如下代码,共16个颜色调用函数。如果要对输出内容进行染色,通过以下代码展示就可以实现!希望对君有用!


#include
#include void print_black()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,0);
} void print_blue()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,1);
}void print_green()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,2);
}void print_reseda()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,3);
}void print_red()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,4);
}void print_purple()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,5);
}void print_yellow()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,6);
}void print_white()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,7);
}void print_gray()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,8);
}void print_bluish()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,9);
}void print_ondine()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,10);
}void print_light_ondine()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,11);
}void print_reddish()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,12);
}void print_lavender()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,13);
}void print_faint_yellow()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,14);
}void print_gloss_while()
{HANDLE hOut; hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hOut,15);
}int main()
{ print_blue(); printf("\t蓝色\n");print_gloss_while();print_green(); printf("\t绿色\n");print_gloss_while();print_reseda(); printf("\t浅绿色\n");print_gloss_while();print_red(); printf("\t红色\n");print_gloss_while();print_purple(); printf("\t紫色\n");print_gloss_while();print_yellow(); printf("\t黄色\n");print_gloss_while();print_white(); printf("\t白色\n");print_gloss_while();print_gray(); printf("\t灰色\n");print_gloss_while();print_bluish(); printf("\t淡蓝色\n");print_gloss_while();print_ondine(); printf("\t淡绿色\n");print_gloss_while();print_light_ondine(); printf("\t淡浅绿色\n");print_gloss_while();print_reddish(); printf("\t淡红色\n");print_gloss_while();print_lavender(); printf("\t淡紫色\n");print_gloss_while();print_faint_yellow(); printf("\t淡黄色\n");print_gloss_while(); printf("\t颜色\n");system("pause");return 0;
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!