You can do this using ANSI Escape Codes. To do this, you need to add, or concatenate, "\033m[38;2;" + <r> + ";" + <g> + ";" + <b> + "m" + <text> + "\033[0m", where <r>, <g>, and <b> are your R, G, and B values respectively and <text> is the string you want to color. "\033m[0m" is necessary to return the style to normal, otherwise all text after would also be colored. You can easily do this using a function.
Code:
#include <iostream>
void rgbText(std::string text, int r, int g, int b) {
//adds color to the text
std::cout << "\033[38;2;" << r << ";" << g << ";" << b << "m" << text << "\033[0m" << std::endl;
}
int main() {
rgbText("This is Cyan!", 0, 255, 255); //Cyan Color
rgbText("This is Red!", 255, 0, 0); //Red Color
return 0;
}
Output:
This is Cyan!
This is Red!