手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

c语言改变输出颜色

时间:2024-10-21 06:37:19

1、首先我们来打印一个hello world!会发现输出的字体是白色的。#include <stdio.h>int main(){ printf("hello world!\n");}

c语言改变输出颜色

2、接下来我们来设置一个函数来改变颜色,记得加头文件#include <windows.h>代码如下:#include <stdi泠贾高框o.h>#include <windows.h>void color(int x) //设置字体颜色{ if(x>=0 && x<=15) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x); else SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);}int main(){ color(6); //在打印前设置颜色,6是黄色 printf("hello world!\n");}

c语言改变输出颜色

3、根据需要选择输出的颜色。其他颜色的值为:  0=黑色 8=灰色     1=蓝色 9=淡蓝色      2=绿色 10=淡绿色     3=湖蓝色 11=淡浅绿色   4=红色 12=淡红色    5=紫色 13=淡紫色     6=黄色 14=淡黄色     7=白色 15=亮白色

© 手抄报圈