Tell me how to adjust the text color in the console? Well, what would you like to write? COLOR_WINDOWTEXT? And How?

Added.

Well, for example, for the Hello world program to display green letters on the screen.

#include <iostream> using namespace std; int main() { cout << "Hello world!" << endl; return 0; } 
  • Speech about the program for Windows? - gecube
  • Yes. - fly399
  • Well, for example, that the program Hellow world would display green letters on the screen. #include <iostream> using namespace std; int main () {cout << "Hello world!" << endl; return 0; } - fly399 pm
  • something not really helped ... - fly399

2 answers 2

In Visual C ++, setting the color of subsequent text, for example, in red is done like this:

 HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(handle, FOREGROUND_RED); 

To build connect windows.h.

And in Borland C ++ like this:

 textcolor(RED); 

For assembly, connect conio.h.

  • It helped! - fly399
  • and how to make something so that the color was only in the cout << "HERE"; - fly399 4:34 pm
  • Redefine the operator << - AlexDenisov
  • 2
 // устанавливает цвет текста и подложки в консоли // 2 - значение цвета фона, 0 - значение цвета текста system("color 20" ); cout << "TEXT"; 

Attributes of colors are set in the form of TWO hexadecimal digits - the first one sets the background color, and the second one defines the foreground color. Each digit can have the following meanings:

  • 0 = Black 8 = Gray
  • 1 = Blue 9 = Light Blue
  • 2 = Green A = Light green
  • 3 = Blue B = Light Blue
  • 4 = Red C = Light Red
  • 5 = Lilac D = Light purple
  • 6 = Yellow E = Light Yellow
  • 7 = White F = Bright White