Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #define ANSI_COLOR_RED "\x1b[31m"
- #define ANSI_COLOR_GREEN "\x1b[32m"
- #define ANSI_COLOR_YELLOW "\x1b[33m"
- #define ANSI_COLOR_BLUE "\x1b[34m"
- #define ANSI_COLOR_MAGENTA "\x1b[35m"
- #define ANSI_COLOR_CYAN "\x1b[36m"
- #define ANSI_COLOR_RESET "\x1b[m"
- using namespace std;
- class FileOutputStream
- {
- public:
- FileOutputStream(char* filename): file_(fopen(filename, "w"))
- {}
- void print(int t)
- {
- fprintf(file_, "%d", t);
- }
- void print(double t)
- {
- fprintf(file_, "%f", t);
- }
- void print(char* name)
- {
- fprintf(file_, "%s", name);
- }
- void flush()
- {
- fflush(file_);
- }
- ~FileOutputStream()
- {
- fclose(file_);
- }
- public:
- FileOutputStream(FILE* file): file_(file)
- {}
- private:
- FileOutputStream& operator = (FileOutputStream const&);
- FileOutputStream(FileOutputStream const&);
- private:
- FILE* file_;
- };
- class ConsoleOutputStream : public FileOutputStream
- {
- public:
- ConsoleOutputStream() : FileOutputStream(stdout)
- {}
- void setColor(const char* str)
- {
- printf(str);
- }
- ~ConsoleOutputStream() {}
- };
- class ErrorOutputStream : FileOutputStream
- {
- public:
- ErrorOutputStream() : FileOutputStream(stderr) {}
- void print(const char* name, const char* file, const char* func, int line)
- {
- cout << name << ' ' << file << ' ' << func << ' ' << line;
- }
- ~ErrorOutputStream() { }
- };
- int main (int argc, char const *argv[])
- {
- ConsoleOutputStream a;
- ErrorOutputStream s;
- a.setColor(ANSI_COLOR_RED);
- s.print("Error!!", __FILE__, __FUNCTION__, __LINE__);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement