在linux下,可以使用一些宏,加上自定义格式输出,让输出更易于调试:

排版出来可能有些乱,注意do{ }while(0);是在一行里就可以了。

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define DEBUG1( fmt,  arg  ... )  \
  4. do{printf("[DEBUG] " fmt ,  ##arg );  }while(0);
  5. #define DEBUG2( fmt,  arg  ... ) \
  6. do{printf("[%s: %s: line %d]" fmt ,\
  7. __FILE__, __FUNCTION__, __LINE__,  ##arg );  }while(0);
  8. #define PrintColor1( fmt,  arg  ... )   \
  9. do{printf("\033[30m""[%s: %s: line %d]" fmt"\033[0m" ,\
  10. __FILE__, __FUNCTION__, __LINE__,  ##arg );  }while(0);
  11. #define PrintColor2( fmt,  arg  ... )   \
  12. do{printf("\033[31m""[%s: %s: line %d]" fmt"\033[0m" ,\
  13. __FILE__, __FUNCTION__, __LINE__,  ##arg );  }while(0);
  14. #define PrintColor3( fmt,  arg  ... )   \
  15. do{printf("\033[32m""[%s: %s: line %d]" fmt"\033[0m" ,\
  16. __FILE__, __FUNCTION__, __LINE__,  ##arg );  }while(0);
  17. #define PrintColor4( fmt,  arg  ... )   \
  18. do{printf("\033[33m""[%s: %s: line %d]" fmt"\033[0m" ,\
  19. __FILE__, __FUNCTION__, __LINE__,  ##arg );  }while(0);
  20. #define PrintColor5( fmt,  arg  ... )   \
  21. do{printf("\033[34m""[%s: %s: line %d]" fmt"\033[0m" ,\
  22. __FILE__, __FUNCTION__, __LINE__,  ##arg );  }while(0);
  23. #define PrintColor6( fmt,  arg  ... )   \
  24. do{printf("\033[35m""[%s: %s: line %d]" fmt"\033[0m" ,\
  25. __FILE__, __FUNCTION__, __LINE__,  ##arg );  }while(0);
  26. #define PrintColor7( fmt,  arg  ... )    \
  27. do{printf("\033[36m""[%s: %s: line %d]" fmt"\033[0m" ,\
  28. __FILE__, __FUNCTION__, __LINE__,  ##arg );  }while(0);
  29. int main()
  30. {
  31. printf("I AM IN macro.c\n");
  32. DEBUG1("I AM IN macro.c\n");
  33. DEBUG2("I AM IN macro.c\n");
  34. PrintColor1("I AM IN macro.c\n");
  35. PrintColor2("I AM IN macro.c\n");
  36. PrintColor3("I AM IN macro.c\n");
  37. PrintColor4("I AM IN macro.c\n");
  38. PrintColor5("I AM IN macro.c\n");
  39. PrintColor6("I AM IN macro.c\n");
  40. PrintColor7("I AM IN macro.c\n");
  41. return 0;
  42. }

输出结果:

 
http://blog.csdn.net/xiangpingli/article/details/7914133

Linux彩色输出的更多相关文章

  1. linux打印彩色输出

    在终端生成彩色输出,我们可以使用转义序列来实现. 每种颜色都有对应的颜色码.比如:重置=0,黑色=30,红色=31,绿色=32,黄色=33,蓝色=34,洋红=35,青色=36,白色=37 要打印彩色文 ...

  2. std::cout彩色输出

    Mac OS效果 Windows 效果 想写这个东西其实是因为最近要写个命令行的工具,但是有个问题是什么呢?就是传统的那个黑漆漆的窗口看起来很蛋疼.并且完全看不到重点,于是就想起 来这么一个东西.相对 ...

  3. SpringBoot之彩色输出

    spring.output.ansi.enabled NEVER:禁用ANSI-colored输出(默认项) DETECT:会检查终端是否支持ANSI,是的话就采用彩色输出(推荐项) ALWAYS:总 ...

  4. Linux seq_printf输出内容不完整的问题

    Linux seq_printf输出内容不完整的问题 写在前面的话:这是多年前在项目中遇到的问题,作为博客的开篇之作,有不足之处,请各位大侠斧正!谢谢! seq_file接口介绍 有许多种方法能够实现 ...

  5. Git设置彩色输出

    彩色输出 git config --global color.status auto git config --global color.diff auto git config --global c ...

  6. Linux下输出 excel文件

    Linux下输出 excel文件 今日提供给产品需求,需excel文件,故总结要点如下: 1.默认间隔是space_20 2.修改为TAB \t _09 awk '  BEGIN { OFS=&quo ...

  7. Linux命令输出头(标题)、输出结果排序技巧

    原文:http://blog.csdn.net/hongweigg/article/details/65446007 ----------------------------------------- ...

  8. 花里胡哨,如何在Linux终端输出带有颜色的字体,将带颜色的字体赋值给变量

    背景 ​ 在日常操作Linux的情况下,总会遇到一些需求,比如说,把输出的内容用不同颜色标注出来,以达到醒目.提示的目的,那么如何在Linux终端输出带有颜色的字体呢? Linux终端输出字符颜色 ​ ...

  9. 通过printf设置Linux终端输出的颜色和显示方式

    转载自:http://www.cnblogs.com/clover-toeic/p/4031618.html 在Linux终端下调试程序时,有时需要输出大量信息.若能控制字体的颜色和显示方式,可使输出 ...

随机推荐

  1. 启动程序的c++方法

    #include <Windows.h> void main() { WinExec( "notepad.exe fitdata.txt", SW_SHOW ); // ...

  2. HTML5 canvas绘制线条曲线

    HTML5 canvas入门 线条例子 1.简单线条 2.三角形 3.填充三角形背景颜色 4.线条颜色以及线条大小 5.二次贝塞尔曲线 6.三次贝塞尔曲线 <!doctype html> ...

  3. 以Ajax的方式访问数据库

    一:以Ajax的方式显示数据 我们都知道,如果用Ajax程序去加载一个动态页,则加载的实际上是这个动态页执行完毕后生成的静态HTML代码字符串. 1.以原有的格式显示数据 <?php heade ...

  4. codevs 1913 数字梯形问题 费用流

    题目链接 给你一个数字梯形, 最上面一层m个数字, 然后m+1,......m+n-1个. n是层数. 在每个位置, 可以向左下或右下走.然后让你从最顶端的m个数字开始, 走出m条路径, 使得路过的数 ...

  5. SpringDataRedis事务处理

    public Long leftPush(V value) { return this.ops.leftPush(this.getKey(), value); } public Long leftPu ...

  6. elasticsearch 索引 类型 id

    zjtest7-frontend:/usr/local/logstash-2.3.4/config# cat logstash_indexer01.conf  input {         redi ...

  7. POJ——位查询

    3:位查询 查看 提交 统计 提问 总时间限制:  5000ms  内存限制:  65536kB 描述 给出N个范围在[0, 65535]的整数,编程支持以下的操作: (1)修改操作:C d,所有的数 ...

  8. 弗洛伊德(Floyd)算法

    #include <stdio.h> #define MAXVEX 20 //最大顶点数 #define INFINITY 65535 //∞ typedef struct {/* 图结构 ...

  9. iOS使用sqlite3原生语法进行增删改查以及FMDB的使用

    首先要导入libsqlite3.dylib并且加入头文件#import <sqlite3.h>,在进行增删改查之前还要先把数据库搞进去. 一种方法是从外面拷贝到程序里:http://www ...

  10. [置顶] hdu2815 扩展Baby step,Giant step入门

    题意:求满足a^x=b(mod n)的最小的整数x. 分析:很多地方写到n是素数的时候可以用Baby step,Giant step, 其实研究过Baby step,Giant step算法以后,你会 ...