its actually quite simple
template <typename T>
void printrgb(int r, int g, int b, T output) {
std::cout<<"\033[38;2;"<<r<<";"<<g<<";"<<b<<"m"<<output<<"\033[0m";
}
the output will be printed based on r, g and b, actually i dont understand how its work