Is it possible to set the color of the message, which I will display on the command line using std::cout , so that the color of all previous messages does not change (that is, multi-colored text)?

  • yes, you can - SetConsoleTextAttribute color to the desired one and before that you memorize the old color, then output the necessary characters to the console and then SetConsoleTextAttribute with the "old" color again. - Duracell
  • Already figured out. To return the old white color of the labels, it is enough to register: SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); - zergon321

1 answer 1

Yes, this is possible using the SetConsoleTextAttribute function:

 BOOL SetConsoleTextAttribute(HANDLE hConsoleOutput, WORD wAttributes) 

Where:

 hConsoleOutput — handle окна wAttributes — набор атрибутов 

Here you can see the attributes themselves.

In your case, the handle can be obtained like this:

 HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);