c 2b 2b console color some digits

Solutions on MaxInterview for c 2b 2b console color some digits by the best coders in the world

showing results for - "c 2b 2b console color some digits"
Camilo
15 Oct 2018
1#include "colormod.h" // namespace Color
2#include <iostream>
3using namespace std;
4int main() {
5    Color::Modifier red(Color::FG_RED);
6    Color::Modifier def(Color::FG_DEFAULT);
7    cout << "This ->" << red << "word" << def << "<- is red." << endl;
8}
9
10#include <ostream>
11namespace Color {
12    enum Code {
13        FG_RED      = 31,
14        FG_GREEN    = 32,
15        FG_BLUE     = 34,
16        FG_DEFAULT  = 39,
17        BG_RED      = 41,
18        BG_GREEN    = 42,
19        BG_BLUE     = 44,
20        BG_DEFAULT  = 49
21    };
22    class Modifier {
23        Code code;
24    public:
25        Modifier(Code pCode) : code(pCode) {}
26        friend std::ostream&
27        operator<<(std::ostream& os, const Modifier& mod) {
28            return os << "\033[" << mod.code << "m";
29        }
30    };
31}
Lynsey
13 Jan 2017
1 cout << "\033[1;31mbold red text\033[0m\n";
Erika
08 Nov 2018
1#include <ostream>
2namespace Color {
3    enum Code {
4        FG_RED      = 31,
5        FG_GREEN    = 32,
6        FG_BLUE     = 34,
7        FG_DEFAULT  = 39,
8        BG_RED      = 41,
9        BG_GREEN    = 42,
10        BG_BLUE     = 44,
11        BG_DEFAULT  = 49
12    };
13    class Modifier {
14        Code code;
15    public:
16        Modifier(Code pCode) : code(pCode) {}
17        friend std::ostream&
18        operator<<(std::ostream& os, const Modifier& mod) {
19            return os << "\033[" << mod.code << "m";
20        }
21    };
22}