We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8b2ee46 commit 6b18a0fCopy full SHA for 6b18a0f
1 file changed
控制台打印带颜色的进度条.c
@@ -0,0 +1,29 @@
1
+#include<stdio.h>
2
+#include<stdlib.h>
3
+#include<windows.h>
4
+
5
+int main(){
6
+ HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
7
+ WORD wOldColorAttrs;
8
+ CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
9
10
+ // 保存起始环境颜色
11
+ GetConsoleScreenBufferInfo(h, &csbiInfo);
12
+ wOldColorAttrs = csbiInfo.wAttributes;
13
14
+ int j=0,i=0;
15
+ while(j++<10)
16
+ {
17
+ printf("这是第");
18
+ // 修改为指定颜色
19
+ SetConsoleTextAttribute(h, FOREGROUND_RED | FOREGROUND_INTENSITY | BACKGROUND_GREEN);
20
+ printf("%d",j);
21
+ // 重置为原来的环境
22
+ SetConsoleTextAttribute(h, wOldColorAttrs);
23
+ printf("次输出------");
24
+ //for(i=0;i<1000000000;i++);
25
+ Sleep(1000);
26
+ printf("\r");
27
+ }
28
+ return 0;
29
+}
0 commit comments