<Knowledge Sharing> here is a function for setting text attributes. The prototype is BOOL SetConsoleTextAttribute (// HANDLE hConsoleOutput, // handle WORD wAttributes // text attributes); By The Way, text attributes are actually color attributes, including the background color and foreground color (that is, the character color, each category only provides three primary colors (red, green, and blue) and enhanced colors (gray, which can be used with other colors to make the colors brighter, as will be mentioned later ). Finally, there is a reversed color (I don't know how to use it, it's amazing ). The example program is as follows: # include <stdio. h> # include <stdlib. h> # include <windows. h> # include <conio. h>/* basic text attributes FOREGROUND_BLUE FOREGROUND_GREEN green highlighted red enhanced BACKGROUND_BLUE background BACKGROUND_GREEN green background BACKGROUND_RED red background enhanced background color reversed */const WORD FORE_BLUE = FOREGROUND_BLUE; // blue text attribute const WORD FORE_GREEN = FOREGROUND_GREEN; // green text attribute const WORD FORE_RED = FOREGROUND_RED; // red text attribute const WORD FORE_PURPLE = FORE_BLUE | FORE_RED; // purple text attribute const WORD FORE_CYAN = FORE_BLUE | FORE_GREEN; // blue text attribute const WORD FORE_YELLOW = FORE_RED | FORE_GREEN; // yellow text attribute const WORD FORE_GRAY = FOREGROUND_INTENSITY; // The gray text attribute const WORD BACK_BLUE = BACKGROUND_BLUE; // the blue background attribute const WORD BACK_GREEN = BACKGROUND_GREEN; // The green background attribute const WORD BACK_RED = BACKGROUND_RED; // green background attribute const WORD BACK_PURPLE = BACK_BLUE | BACK_RED; // purple background attribute const WORD BACK_CYAN = BACK_BLUE | BACK_GREEN; // blue background attribute const WORD BACK_YELLOW = BACK_RED | BACK_GREEN; // The Yellow background property const WORD BACK_GRAY = BACKGROUND_INTENSITY; // The gray background property int main () {HANDLE handle_out = GetStdHandle (STD_OUTPUT_HANDLE); // obtain the HANDLE of the standard output device CONSOLE_SCREEN_BUFFER_INFO csbi; // define the window buffer information structure GetConsoleScreenBufferInfo (handle_out, & csbi); // obtain the window buffer information SetConsoleTextAttribute (handle_out, FORE_BLUE); printf ("blue character \ n "); setConsoleTextAttribute (handle_out, FORE_RED); printf ("Red character \ n"); SetConsoleTextAttribute (handle_out, FORE_GREEN); printf ("Green character \ n"); SetConsoleTextAttribute (handle_out, FORE_PURPLE); printf ("Purple character \ n"); SetConsoleTextAttribute (handle_out, FORE_CYAN); printf ("cyan character \ n"); SetConsoleTextAttribute (handle_out, FORE_YELLOW ); printf ("Yellow character \ n"); SetConsoleTextAttribute (handle_out, FORE_GRAY); printf ("gray character \ n"); SetConsoleTextAttribute (handle_out, FORE_GREEN | FORE_BLUE | FORE_RED ); printf ("White character \ n"); SetConsoleTextAttribute (handle_out, BACK_BLUE); printf ("blue background \ n"); SetConsoleTextAttribute (handle_out, BACK_RED ); printf ("red background \ n"); SetConsoleTextAttribute (handle_out, BACK_GREEN); printf ("green background \ n"); SetConsoleTextAttribute (handle_out, BACK_PURPLE ); printf ("purple background \ n"); SetConsoleTextAttribute (handle_out, BACK_CYAN); printf ("cyan background \ n"); SetConsoleTextAttribute (handle_out, BACK_YELLOW ); printf ("Yellow background \ n"); SetConsoleTextAttribute (handle_out, BACK_GRAY); printf ("gray background \ n"); SetConsoleTextAttribute (handle_out, BACK_BLUE | BACK_RED | BACK_GREEN ); printf ("white background \ n"); SetConsoleTextAttribute (handle_out, BACK_GREEN | FORE_RED); // example: green background red character printf ("green background and red character mix \ n"); SetConsoleTextAttribute (handle_out, FOREGROUND_INTENSITY | FORE_RED); // example: bright red character printf ("generation of bright colors, fusion with enhanced colors \ n"); return 0;