console colors in c 2b 2b

Solutions on MaxInterview for console colors in c 2b 2b by the best coders in the world

showing results for - "console colors in c 2b 2b"
Adriana
28 Jul 2018
1//This is a header file taken from cplusplus.com
2//http://www.cplusplus.com/articles/Eyhv0pDG/
3//concol.h
4#ifndef _INC_EKU_IO_CONCOL
5#define _INC_EKU_IO_CONCOL
6
7/*Header file to color text and background in windows console applications
8Global variables - textcol,backcol,deftextcol,defbackcol,colorprotect*/
9
10#include<windows.h>
11#include<iosfwd>
12
13namespace eku
14{
15
16#ifndef CONCOL
17#define CONCOL
18	enum concol
19	{
20		black=0,
21		dark_blue=1,
22		dark_green=2,
23		dark_aqua,dark_cyan=3,
24		dark_red=4,
25		dark_purple=5,dark_pink=5,dark_magenta=5,
26		dark_yellow=6,
27		dark_white=7,
28		gray=8,
29		blue=9,
30		green=10,
31		aqua=11,cyan=11,
32		red=12,
33		purple=13,pink=13,magenta=13,
34		yellow=14,
35		white=15
36	};
37#endif //CONCOL
38
39	HANDLE std_con_out;
40	//Standard Output Handle
41	bool colorprotect=false;
42	//If colorprotect is true, background and text colors will never be the same
43	concol textcol,backcol,deftextcol,defbackcol;
44	/*textcol - current text color
45	backcol - current back color
46	deftextcol - original text color
47	defbackcol - original back color*/
48
49	inline void update_colors()
50	{
51		CONSOLE_SCREEN_BUFFER_INFO csbi;
52		GetConsoleScreenBufferInfo(std_con_out,&csbi);
53		textcol = concol(csbi.wAttributes & 15);
54		backcol = concol((csbi.wAttributes & 0xf0)>>4);
55	}
56
57	inline void setcolor(concol textcolor,concol backcolor)
58	{
59		if(colorprotect && textcolor==backcolor)return;
60		textcol=textcolor;backcol=backcolor;
61		unsigned short wAttributes=((unsigned int)backcol<<4) | (unsigned int)textcol;
62		SetConsoleTextAttribute(std_con_out,wAttributes);
63	}
64
65	inline void settextcolor(concol textcolor)
66	{
67		if(colorprotect && textcolor==backcol)return;
68		textcol=textcolor;
69		unsigned short wAttributes=((unsigned int)backcol<<4) | (unsigned int)textcol;
70		SetConsoleTextAttribute(std_con_out,wAttributes);
71	}
72
73	inline void setbackcolor(concol backcolor)
74	{
75		if(colorprotect && textcol==backcolor)return;
76		backcol=backcolor;
77		unsigned short wAttributes=((unsigned int)backcol<<4) | (unsigned int)textcol;
78		SetConsoleTextAttribute(std_con_out,wAttributes);
79	}
80
81	inline void concolinit()
82	{
83		std_con_out=GetStdHandle(STD_OUTPUT_HANDLE);
84		update_colors();
85		deftextcol=textcol;defbackcol=backcol;
86	}
87
88	template<class elem,class traits>
89	inline std::basic_ostream<elem,traits>& operator<<(std::basic_ostream<elem,traits>& os,concol col)
90	{os.flush();settextcolor(col);return os;}
91
92	template<class elem,class traits>
93	inline std::basic_istream<elem,traits>& operator>>(std::basic_istream<elem,traits>& is,concol col)
94	{
95		std::basic_ostream<elem,traits>* p=is.tie();
96		if(p!=NULL)p->flush();
97		settextcolor(col);
98		return is;
99	}
100	
101}	//end of namespace eku
102
103#endif	//_INC_EKU_IO_CONCOL
April
04 Nov 2019
1//This is one way to do it. Taken from stackoverflow.
2system("color 70");
3//It just runs a cmd command.
queries leading to this page
windows cmd std 3a 3acout colorc 2b 2b colors in consolec 2b 2b console text colorc 2b 2b console change text color 3cconcepts 3ecolors in c 2b 2b consolec 2b 2b print colored text windowsc 2b 2b windows colorconsole color codes c 2b 2bchange color of console text in c 2b 2bchange text color c 2b 2b consolecolors with c 2b 2bc 2b 2b windows set console colorcpp console colourconsole text attribute in c 2b 2bconsole attributes c 2b 2b colorscolor in c 2b 2b consolec 2b 2b printing in color in windowsdc 2b 2b change text color consoleprint in color windows h ccpp color text cmdwindows colors terminal c 2b 2bcolors in console c 2b 2bc 2b 2b console color codescolors in console using c 2b 2bconsole text color c 2b 2bc 2b 2b console app colourc 2b 2b cmd color textchange console text mode c 2b 2bchange output color in c 2b 2b console cout console color in c 2b 2bconsole text color c 2fc 2b 2bc 2b 2b change console attrivutesreset console text attribute c 2b 2bc 2b 2b console colorchanging console color c 2b 2bc 2b 2b command line colorc 2b 2b colors consolecolor in c 2b 2b output windowsc 2b 2b set color consolecpp use colorloop through every system color c 2b 2bc 2b 2b set console text colorset console pink c 2b 2bhow to change color of console in c 2b 2bconsola colors c 2b 2brand color terminal cppc 2b 2b system color a1 listhow to change letter color in console c 2b 2bconsole colors c 2b 2bc 2b 2b change color consolerun c 2b 2b in cmd but no colorc 2b 2b coloured text in consoleconsole color c 2b 2bc 2b 2b text color consolehow to change output color in c 2b 2b windowschange console color c 2b 2bcolorize screen c 2b 2bchange color of console in c 2b 2bcolor writing c 2b 2b cmdcan i change cmd colors in code c 2b 2bc 2b 2b change console colorbest console color in c 2b 2bc 2b 2b cout color windowswhat coloring does c 2b 2b usec 2b 2b color console textcolors c 2b 2bc 2b 2b system color codesc 2b 2b console text color multiplatformhow to make text console with windows hc 2b 2b print colored characters on consolehow to use color c 2b 2bc 2b 2b change console color simplec 2b 2b console colour numberssystem 28 22color 1a 22 29 3b all colorsc 2b 2b coloured consolecolor text c 2b 2b consolechange console color text c 2b 2bcolour full console in c 2b 2bc 2b 2b colored consolec 2b 2b windows color consolec 2b 2b colored output windowshow to return a console color c 2b 2bred text c 2b 2bstd 3a 3acout color windowscolor console c 2b 2bhow to give green color output in cmd cpp codec 2b 2b color consolec 2b 2b console colourscolor in the cmd code c 2b 2bc 2b 2b output color text windowswindows h c print in colorcolor cycle c 2b 2b with whitec 2b 2b color in cmdc 2b 2b consoleatribute colorsc 2b 2b change color of console texthow to change console color in c 2b 2bc 2b 2b color console codesc 2b 2b console color outputsetconsoletextattribute c 2b 2b colorsc 2b 2b custom console colorsc 2b 2b console colourwindows h console color examplesconsole colors in c 2b 2bc 2b 2b console color textconsole colour c 2b 2bcolor default consola c 2b 2bhow to change the color of the console text in c 2b 2bchange color console c 2b 2bchange color of console c 2b 2bc 2b 2b set console colorc 2b 2b console colorscolors in windows hchange console text color c 2b 2bcpp console coolorc 2b 2b console individual colorc 2b 2b white consoleblack color for console output c 2b 2badd color to console c 2b 2bconsole color cpphow to change terminal color in c 2b 2bc 2b 2b how to print colored text to consolec 2b 2b colored text powershellwhy my c 2b 2b output in cmd no colorc 2b 2b cout in colour windowsc 2b 2b console change colorhow to change font color in c 2b 2b consolec 2b 2b change std 3a 3acout color windowsset console text c 2b 2b colorscolor default console c 2b 2bcolor c 2b 2b consoleregular colors with c 2b 2bcpp highlight consolehow to change console text color in c 2b 2bcolored c 2b 2b consolecpp color codes system colorc 2b 2b log colorc 2b 2b colored asciihow to write with color to terminal with c 2b 2bset console color in c 2b 2bcolor text for console c 2b 2bchange color c 2b 2b consolechange console colour c 2b 2bdifferent console text colors in c 2b 2bhow to set console output color in c 2b 2bhow to change the console text color in c 2b 2bprint colored text c 2b 2b windowscolor console characters c 2b 2bset console color c 2b 2bcolors in c 2b 2bcpp set console colorshowing colour text in c 2b 2b consoleprint in console with colors c 2b 2bc 2b 2b red colorc 2b 2b console font colorcolor in c 2b 2bc 2b 2b how to change console colorcolor text console c 2b 2bhighlight text console c 2b 2bvisual c 2b 2b console character colorc 2b 2b what is col codehow to add colors to console in c 2b 2bc 2b 2b cout 3c 3c color text windowscolor writing c 2b 2b consolec 2b 2b color terminal windowschange text color in c 2b 2b consolecolor cppchange terminal color c 2b 2bwindows h console color exerciseswindows console colors c 2b 2bc 2b 2b color text consolec 2b 2b colorsdefault console text color in c 2b 2bhow to change color console in c 2b 2bcolors in the console in c 2b 2badd color ti c 2b 2b command lineconsole colors in c 2b 2b