How to color highlight text output in terminal (C++ and Windows)

Tried some notations, but they cover each other and look so dirty.
kindly advise
Here's an example of changing the text color and the background of specific words on the console.
https://stackoverflow.com/questions/20725769/change-background-color-of-console-output-in-c-and-c

It should be noted that the code is Windows specific, I'm not aware of any C/C++ standard way to specify these values.
I've read that this type of action is done by communicating with the terminal emulator, so it is probably not guaranteed to work between all the different terminals on Windows either; though the "Windows Console" is going to be available on all Windows systems, there is a chance that your user has downloaded a bash terminal emulator or similar.

Last edited on
You're going to have to use the Windows API.

SO: Colorizing text in the console with C++
https://stackoverflow.com/questions/4053837/colorizing-text-in-the-console-with-c
From Windows 10 onwards, you can use Virtual Terminal Sequences (based upon VT100 escape codes). See:
https://learn.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
Since the OP mentioned Windows here's an older Win-centric header-only method here at CPlusPlus that still works with Win10:

https://cplusplus.com/articles/Eyhv0pDG/

I can't say if it works with Win11, I don't have that.
Topic archived. No new replies allowed.