The
color has nothing to do with C++. It doesn't even have anything to do with "Windows library"*.
1. Open Windows Terminal (the
cmd).
2. Type in terminal:
help color
The
color is (at least effectively) an entirely separate MS-specific program that does send instructions to the MS GUI terminal window. Your program happens to / attempts to execute that external program.
This program uses "a library":
1 2 3 4 5
|
#include <iostream>
int main() {
std::cout << "Hello\n";
}
|
The
std::cout
is a global variable that is declared and defined elsewhere. We can use it, because we include header "iostream" into our source code and link the library file(s) with our binary.
The
<<
is a function that we call, and its implementation in linked library will do the work. The implementation will interact with terminal window to pass the string for display rendering.
The "Windows library" may or may not have functions that you could call in order to modify the colour attributes of the GUI window of the terminal, where your program happens to run.
Alas, CMD terminal is not the only implementation of terminal. Most of the other programs understand common formatting instructions, but CMD is not one of them. Do note that even though MS Windows dominates (some) market, most users of MS Windows do not use the CMD terminal. Ever.
Therefore, your approach to "format output" is limited to a niche product.
There are third party libraries that have been ported to translate "GUI formatting" to multiple terminal types, including the CMD.
*Our concept of what is a "library" might differ.