Display color output with C/C++ in windows terminal (fix escape characters color displaying)
On windows when you will try to display \033[0m or \x1B[31m and so one, instead of getting color in terminal you will get ]31m. On windows 10 and letter itβs pretty easy to fix. You just need to include next code:
1
2
3
4
5
6
7
8
9
10
11
#include <windows.h>
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (hConsole)
{
DWORD consoleMode;
GetConsoleMode(hConsole, &consoleMode);
SetConsoleMode(hConsole, consoleMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
}
// now you can use color printf()