Unsolved Hi ,I am unable to print on console with different different colors and background which is my project demand ,I also tried the ANSI sys type of printi yet i didnt find the solution can anybody help me in this regard.
-
-
Hi and welcome to devnet,
Please give your thread a meaningful summary and put your question and related information in the body of the post.
-
I vaguely remember that modern windoze cmd.exe doesn't support ansi control sequences anymore.
-
@Kent-Dorfman
Indeed!@Dhanush_Gowda
You may have to read through https://stackoverflow.com/questions/16755142/how-to-make-win32-console-recognize-ansi-vt100-escape-sequences. -
On Windows you just need to enable virtual terminal processing (include
Windows.h
):DWORD mode; HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleMode(h, &mode); SetConsoleMode(h, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); printf("\033[31mRed\033[32mGreen\033[34mBlue");
or you can go native and use console APIs directly:
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(h, FOREGROUND_RED); printf("Red"); SetConsoleTextAttribute(h, FOREGROUND_GREEN); printf("Green"); SetConsoleTextAttribute(h, FOREGROUND_BLUE); printf("Blue");