Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
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.
Dhanush_Gowda last edited by
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.
Kent-Dorfman last edited by
I vaguely remember that modern windoze cmd.exe doesn't support ansi control sequences anymore.
JonB last edited by JonB
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
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");