#define中#和##的作用

来源:互联网 发布:淘宝tbi数据包怎么用 编辑:程序博客网 时间:2024/05/17 23:24

###Date:2017/9/29

     在学习的过程中发现,宏函数的作用还是很大的。通过使用宏函数可以有效减少函数的声明。通过连接符##可以实现这一点。下面就记录一下#define中#和##的作用。

     #:字符串化,宏定义中的#是把跟在后面的参数转成一个字符串;

   ##:连接字符串

例子:

#include <iostream>using namespace std;#define to_string(s) #s#define test_macro  "hello"##"world"int main(int argc, char* argv[]){cout << to_string(Hello World!) << endl;cout << test_macro << endl;return 0;}

输出分别为:Hello World!

                      helloworld

参考:

     http://blog.csdn.net/qq_15457239/article/details/56842450

     http://www.cnblogs.com/little-ant/p/3463080.html

原创粉丝点击