'Change color of variables in c++ output

Im making a wordle game and it would make everything much easier if i could code colors into the game, so the output goes from:

flame
__&_!
-----
-----
-----
-----
-----

where i use symbols, to something more like real wordle with colors:

enter image description here

Im using emacs on a linux server and i can color the output of strings using

\033[1;31m Sample Text \033[0m

to change the color of strings but i need a way of changing the variable output color, something along the lines of this:

string word = "water";
cout << \033[1;31m word \033[0m << endl;

because if i just use the quotes its not going to use the variable it will just print "word"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source