output to console in color c++

To output text in color in C++, you can use escape sequences. Below is an example of how to output text in different colors to the console using C++:

#include <iostream>

int main() {
    std::cout << "\033[1;31mThis is red text\033[0m" << std::endl;
    std::cout << "\033[1;32mThis is green text\033[0m" << std::endl;
    std::cout << "\033[1;33mThis is yellow text\033[0m" << std::endl;
    std::cout << "\033[1;34mThis is blue text\033[0m" << std::endl;
    std::cout << "\033[1;35mThis is magenta text\033[0m" << std::endl;
    std::cout << "\033[1;36mThis is cyan text\033[0m" << std::endl;
    return 0;
}

Explanation: - #include <iostream>: This line includes the necessary library for input/output operations. - std::cout: This is the standard output stream used to display text to the console. - \033[1;31m: This escape sequence sets the color to red. The 1 stands for bold, and 31 represents the color code for red. - This is red text: This is the text that will be displayed in red. - \033[0m: This escape sequence resets the color to the default. - std::endl: This is used to move the cursor to the next line after displaying the text.

The same process is repeated for green, yellow, blue, magenta, and cyan text, using the corresponding color codes in the escape sequences.