How do I make colored text in C++?
Just a beginner in C++, how do I make the most effective code for C++ to make colored text ?
Voters
Coder100
Hi! I put them in a struct
:
struct ColorStruct { std::string reset = "\x1b[0m"; std::string bold = "\x1b[1m"; std::string italic = "\x1b[3m"; std::string underline = "\x1b[4m"; std::string inverse = "\x1b[7m"; std::string black = "\x1b[30m"; std::string red = "\x1b[31m"; std::string green = "\x1b[32m"; std::string yellow = "\x1b[33m"; std::string blue = "\x1b[34m"; std::string magenta = "\x1b[35m"; std::string cyan = "\x1b[36m"; std::string white = "\x1b[37m"; std::string gray = "\x1b[90m"; std::string bright_red = "\x1b[91m"; std::string bright_green = "\x1b[92m"; std::string bright_yellow = "\x1b[93m"; std::string bright_blue = "\x1b[94m"; std::string bright_magenta = "\x1b[95m"; std::string bright_cyan = "\x1b[96m"; std::string bright_white = "\x1b[97m"; std::string bg_black = "\x1b[40m"; std::string bg_red = "\x1b[41m"; std::string bg_green = "\x1b[42m"; std::string bg_yellow = "\x1b[43m"; std::string bg_blue = "\x1b[44m"; std::string bg_magenta = "\x1b[45m"; std::string bg_cyan = "\x1b[46m"; std::string bg_white = "\x1b[47m"; std::string bg_gray = "\x1b[100m"; std::string bg_bright_red = "\x1b[101m"; std::string bg_bright_green = "\x1b[102m"; std::string bg_bright_yellow = "\x1b[103m"; std::string bg_bright_blue = "\x1b[104m"; std::string bg_bright_magenta = "\x1b[105m"; std::string bg_bright_cyan = "\x1b[106m"; std::string bg_bright_white = "\x1b[107m"; }; ColorStruct colors; std::cout << colors.red << "red text" << colors.reset << " normal text";
Read more here
Coder100
Hi! I put them in a struct
:
k9chelsea2
[this] (https://stackoverflow.com/questions/9965710/how-to-change-text-and-background-color) might help im not sure
@Joshuahaojie Hi,
Here are some colors that you can use in C++
Thanks!
Hope this helps
@PattanAhmed Thanks man ! Also, is there any way to change background color?
@Joshuahaojie Welcome!
I think this website might help you now:-
Click here
Thanks!