2015-04-21 10:54:43
1#include <windows.h>2#include <iostream>3 using namespacestd;4 #defineColor_count 155 6 //void SetColor (unsigned short ForeColor = 3, unsigned short backgroundcolor = 0)7 voidSetColor (intcolor)8 {9 if(Color <0|| Color >= the)Ten return; One A StaticWORD Wincolorfg[color_count] = - { - 0,//BLACK theForeground_red,//RED -Foreground_green,//GREEN -foreground_red | Foreground_green,//BROWN -Foreground_blue,//BLUE +foreground_red | Foreground_blue,//MAGENTA -Foreground_green | Foreground_blue,//CYAN +foreground_red | Foreground_green | Foreground_blue,// White Aforeground_red | Foreground_green | Foreground_intensity,//YELLOW atforeground_red | Foreground_intensity,//Red_bold -Foreground_green | Foreground_intensity,//Green_bold -Foreground_blue | Foreground_intensity,//Blue_bold -foreground_red | Foreground_blue | Foreground_intensity,//Magenta_bold -Foreground_green | Foreground_blue | Foreground_intensity,//Cyan_bold -foreground_red | Foreground_green | Foreground_blue | Foreground_intensity//White_bold in }; -HANDLE Hconsole =GetStdHandle (std_output_handle); to Setconsoletextattribute (Hconsole, Wincolorfg[color]); + /*Setconsoletextattribute (hconsole, ForeColor | BackgroundColor);*/ - } the * intMain () $ {Panax Notoginseng for(inti =0; I < the; ++i) - { the SetColor (i); +cout<<"Hello world!"<<Endl; A } the /*SetColor (); + cout<< "Hello world!" <<endl; - SetColor (foreground_red); $ cout<< "Hello world!" <<endl; $ cout<< "Hello world!" <<endl;*/ -System"Pause"); - return 0; the}
Windows DOS window Set Font color