c 2b 2b console color

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

showing results for - "c 2b 2b console color"
Pedro
07 Feb 2020
1WORD color = 0x0F; // White
2SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED);
3cout << "Hello World" << endl;
4SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), color);
5// The farbcodes are the same as they, when you type "color help" in the windows 
6// cmd in. First the number, then the letter (here the output of the cmd):
7/*  0 = Black       8 = Gray
8    1 = Blue        9 = Light Blue
9    2 = Green       A = Light Green
10    3 = Aqua        B = Light Aqua
11    4 = Red         C = Light Red
12    5 = Purple      D = Light Purple
13    6 = Yellow      E = Light Yellow
14    7 = Light Gray  F = White
15    */
16// So, to get the output white again, you have the set the color to:
17// 0x + 0 (Black Background) + F (White Foreground)
18// This works on every OS!
Iker
15 Jan 2021
1SetConsoleTextAttribute(console, ((int)background * 16) + (int)forground);
Lennard
23 Jan 2020
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
Valentín
13 Oct 2020
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
default console text color in c 2b 2bc 2b 2b windows color consolec 2b 2b what is col coderand color terminal cppc 2b 2b system color a1 listhow to write with color to terminal with c 2b 2bcolor console c 2b 2bc 2b 2b change color consolescritte colorate console c 2b 2bcpp change console colorc 2b 2b termcolorwhy my c 2b 2b output in cmd no colorc 2b 2b output color text windowshow to change console background color in c 2b 2bcpp use colorc 2b 2b console colourscpp console coolorhow to change the terminal color in c 2b 2bcolor in the cmd code c 2b 2bc 2b 2b colored output windowsc 2b 2b console individual colorchange console text color c 2b 2bhow to change color in c 2b 2b consolec 2b 2b console color textc 2b 2b colors in consolec 2b 2b console color codeswindows console text color c 2b 2bwindows cmd std 3a 3acout colorcpp highlight consolewindows h console color exercisesadd color ti c 2b 2b command linecolors in console using c 2b 2bshowing colour text in c 2b 2b consolecolor in c 2b 2b consolec 2b 2b console app colourcpp set console color windowsconsole color c 2b 2bc 2b 2b console background colorsetconsoletextattribute c 2b 2b colorscolors in the console in c 2b 2bc 2b 2b cout color windowsc 2b 2b cout 3c 3c color text windowsconsole colors cpphow to change background color in c 2b 2b consolereset console text attribute c 2b 2bcolor text c 2b 2b consolecode for color output in c 2b 2b consolehow to change console line color in c 2b 2bconsole text color c 2fc 2b 2bcpp color text cmdhighlight text console c 2b 2bc 2b 2b change std 3a 3acout color windowschange color c 2b 2b consolehow to change the console text color in c 2b 2bc 2b 2b console colorscolor default console c 2b 2bc 2b 2b change console attrivuteschange console text color c 2b 2b linuxchange console color c 2b 2b linuxc 2b 2b how to print colored text to console 3cconcepts 3echange color character c 2b 2b consolehow to give green color output in cmd cpp codecolor in c 2b 2bhow to change text color in c 2b 2b consolec 2b 2b custom console colorsc 2b 2b colored asciicolor text for console c 2b 2bcpp color consoleprint colored text c 2b 2b windowsconsole colors in c 2b 2bc 2b 2b colored consolec 2b 2b set color consoleset console pink c 2b 2bc 2b 2b print colored text windowshow to change color of console in c 2b 2bcolor in c 2b 2b output windowsc 2b 2b windows set console colorchange color of console in c 2b 2bc 2b 2b console color from rgbchange console background and text color c 2b 2bconsole attributes c 2b 2b colorsset console text c 2b 2b colorsconsole colour c 2b 2bc 2b 2b print colored characters on consoleconsole colors c 2b 2bc 2b 2b cout in colour windowscolors in c 2b 2b consolec 2b 2b colors in terminalchange text color in c 2b 2b consolewhat coloring does c 2b 2b usehow to change font color in c 2b 2b consolechange only text color in c 2b 2b consolec 2b 2b console font colorc 2b 2b change text color consolec 2b 2b coloured consolec 2b 2b color in cmdc 2b 2b console text colorc 2b 2b give color to a text consolec 2b 2b color console codescpp console colourhow to change console text color in c 2b 2bc 2b 2b color terminal windowsloop through every system color c 2b 2bc 2b 2b cmd color textc 2b 2b console colorprint in color windows h cc 2b 2b red colorcolor text console c 2b 2bcolors in c 2b 2bhow to change the system color of your console in c 2b 2bhow to return a console color c 2b 2bc 2b 2b colored text powershellc 2b 2b set console text colorhow to make text console with windows hhow to add colors to console in c 2b 2bc 2b 2b console color windowschange console text mode c 2b 2bhow to change color console in c 2b 2bc 2b 2b console text color multiplatformtext colour windows console c 2b 2bc 2b 2b set console colorchange color console c 2b 2bwindows console colors c 2b 2bchange console color text c 2b 2bc 2b 2b change console colorterminal c 2b 2b colorcpp change console color linuxc 2b 2b white consolec 2b 2b coloured text in consoleblack color for console output c 2b 2bc 2b 2b color text consolerun c 2b 2b in cmd but no colorhow to change terminal color in c 2b 2bcolor cppcolors in console c 2b 2bc 2b 2b system color codesc 2b 2b how to change console colorc 2b 2b console colour numberschange terminal color c 2b 2bc 2b 2b log colorc 2b 2b color console textcolors in windows hc 2b 2b colors consoledifferent console text colors in c 2b 2bcout console color in c 2b 2bc 2b 2b clion colorful terminalwindows h c print in colorsystem 28 22color 1a 22 29 3b all colorsc 2b 2b colorshow to set console output color in c 2b 2bcolor cycle c 2b 2b with whitehow to change the console font colour c 2b 2bcan i change cmd colors in code c 2b 2bc 2b 2b color consoleconsole color in c 2b 2bchange console color c 2b 2bchange output color in c 2b 2b console colors with c 2b 2bcpp set console colorc 2b 2b console color changec 2b 2b console change colorcolors c 2b 2b consolehow to change letter color in console c 2b 2bhow to change console color in c 2b 2bchange terminal color with c 2b 2bset console color in c 2b 2bcpp color codes system colorcolor writing c 2b 2b cmdcolor c 2b 2b consolewindows h console color examplesconsole color cpphow to use color c 2b 2bchange console colour c 2b 2bc 2b 2b console output colorcolor writing c 2b 2b consoleprint in console with colors c 2b 2bcolorize screen c 2b 2bc 2b 2b change console color simplecolor default consola c 2b 2bchanging console color c 2b 2bstd 3a 3acout color windowsconsole color codes c 2b 2bcolors c 2b 2bc 2b 2b text color consolec 2b 2b terminal colorc 2b 2b console colourc 2b 2b command line colorhow to change output color in c 2b 2b windowscolour full console in c 2b 2bconsole text color c 2b 2bc 2b 2b printing in color in windowsdwindows colors terminal c 2b 2bset console color c 2b 2bc 2b 2b set console background color blackconsole text attribute in c 2b 2bdoes console support color c 2b 2bregular colors with c 2b 2bhow to change the color of the console text in c 2b 2bc 2b 2b change color of console textcolor console characters c 2b 2bbest console color in c 2b 2bconsola colors c 2b 2bcolored c 2b 2b consolechange color of console c 2b 2bchange color of console text in c 2b 2bvisual c 2b 2b console character colorhow to change the color of the console in c 2b 2bc 2b 2b set console background colorchange text color c 2b 2b consolec 2b 2b consoleatribute colorsred text c 2b 2bc 2b 2b windows coloradd color to console c 2b 2bc 2b 2b console change text colorc 2b 2b console color outputc 2b 2b console color