1、利用color封装实现个性化颜色输出功能
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define COLOR(msg, code) "\033[0;" #code "m" msg "\033[0m"
#define RED(msg) COLOR(msg, 31)
#define GREEN(msg) COLOR(msg, 32)
#define YELLOW(msg) COLOR(msg, 33)
#define BLUE(msg) COLOR(msg, 34)
int main() {
//printf("\033[0;" "31" "m" "hello kaikeba" "\033[0m\n");
printf(RED("hello\n"));
printf(GREEN("hello\n"));
printf(YELLOW("hello\n"));
printf(BLUE("hello\n"));
printf("hello\n");
return 0;
}
结果:
1、ktest.h
#ifndef _KTEST_H
#define _KTEST_H
#define LOG(frm, args...) { \
printf("[%s : %s : %d] ", __FILE__, __func__, __LINE__); \
printf(frm, ##args); \
printf("\n"); \
}
//实现color系列封装
#define COLOR(msg, code) "\033[0;" #code "m" msg "\033[0m"
#define RED(msg) COLOR(msg, 31)
#define