Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ console color some digits

#include "colormod.h" // namespace Color
#include <iostream>
using namespace std;
int main() {
    Color::Modifier red(Color::FG_RED);
    Color::Modifier def(Color::FG_DEFAULT);
    cout << "This ->" << red << "word" << def << "<- is red." << endl;
}

#include <ostream>
namespace Color {
    enum Code {
        FG_RED      = 31,
        FG_GREEN    = 32,
        FG_BLUE     = 34,
        FG_DEFAULT  = 39,
        BG_RED      = 41,
        BG_GREEN    = 42,
        BG_BLUE     = 44,
        BG_DEFAULT  = 49
    };
    class Modifier {
        Code code;
    public:
        Modifier(Code pCode) : code(pCode) {}
        friend std::ostream&
        operator<<(std::ostream& os, const Modifier& mod) {
            return os << "33[" << mod.code << "m";
        }
    };
}
Comment

c++ console color some digits

 cout << "33[1;31mbold red text33[0m
";
Comment

c++ console color some digits

#include <ostream>
namespace Color {
    enum Code {
        FG_RED      = 31,
        FG_GREEN    = 32,
        FG_BLUE     = 34,
        FG_DEFAULT  = 39,
        BG_RED      = 41,
        BG_GREEN    = 42,
        BG_BLUE     = 44,
        BG_DEFAULT  = 49
    };
    class Modifier {
        Code code;
    public:
        Modifier(Code pCode) : code(pCode) {}
        friend std::ostream&
        operator<<(std::ostream& os, const Modifier& mod) {
            return os << "33[" << mod.code << "m";
        }
    };
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: declare dictionary cpp 
Cpp :: char type casting in c++ 
Cpp :: replace character in a string c++ stack overflow 
Cpp :: non stoichiometric nacl is yellow 
Cpp :: iomanip 
Cpp :: C++ Kilometers Per Hour to Miles Per Hour Conversion 
Cpp :: compile notepad++ c++ 
Cpp :: qt qimage load from file 
Cpp :: rotate in cpp 
Cpp :: border radius layout android xml 
Cpp :: do you need inline for template in C++ 
Cpp :: c++ std::find with lambda 
Cpp :: cpp infinity 
Cpp :: qlabel font color 
Cpp :: input a string in c++ 
Cpp :: Matrix multiply using function c++ 
Cpp :: how to get double y dividing 2 integers in c++ 
Cpp :: c++ vector iterator 
Cpp :: map defualt value c++ 
Cpp :: to_string c++ 
Cpp :: opencv c++ hello world 
Cpp :: read file into vector 
Cpp :: built in led 
Cpp :: strip space from string cpp 
Cpp :: how to convert int to std::string 
Cpp :: for loop with array c++ 
Cpp :: number of characters in c++ files 
Cpp :: c++ random number within range 
Cpp :: c++ get environment variable 
Cpp :: how to easily trim a str in c++ 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =