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.

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++
From Windows 10 onwards, you can use Virtual Terminal Sequences (based upon VT100 escape codes). See:
Since the OP mentioned Windows here's an older Win-centric header-only method here at CPlusPlus that still works with Win10:

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