c windows控制台输出颜色文字
#include <windows.h>
//設置文字顏色
void SetColor(int ForgC)
{
WORD wColor;
//We will need this handle to get the current background attribute
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
//We use csbi for the wAttributes word.
if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
{
//Mask out all but the background attribute, and add in the forgournd color
wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F);
SetConsoleTextAttribute(hStdOut, wColor);
}
}
0 - BLACK 黑 深色0 - 7
1 - BLUE 蘭 2 - GREEN 綠
3 - CYAN 青 4 - RED 紅
5 - MAGENTA 洋紅 6 - BROWN 棕
7 - LIGHTGRAY 淡灰 8 - DARKGRAY 深灰 淡色8 - 15
9 - LIGHTBLUE 淡蘭 10 - LIGHTGREEN 淡綠
11 - LIGHTCYAN 淡青 12 - LIGHTRED 淡紅
13 - LIGHTMAGENTA 淡洋紅 14 - YELLOW 黃
15 - WHITE 白
?
例子:
void print_char() {printf("Game\n");printf("---------------------\n");printf("\n|----|----|----|\n");for(int i=0;i<3;i++){printf("|");for(int j=0;j<3;j++){if (a[i][j]!=0){if (randx == i && randy == j){SetColor(4);printf("%3d",a[i][j]);SetColor(15);printf(" |");}else{SetColor(15);printf("%3d |",a[i][j]); }}else{SetColor(15);printf(" |");}}if(i<=3){printf("\n|____|____|____|\n");}} }
轉載于:https://www.cnblogs.com/wangjian8888/p/9907897.html
總結
以上是生活随笔為你收集整理的c windows控制台输出颜色文字的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 牛客网——华为机试(题15:求int型正
- 下一篇: assert.notStrictEqua