欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

c/c++宏定义,#,## 代码实例

程序员文章站 2023-01-24 19:09:37
# —— 字符串 ##——连接两个参数 #include using namespace std; #d...

# —— 字符串

##——连接两个参数

#include <iostream>
using namespace std;

#define test(pid) (cout<<para##pid<<endl);
#define test2(p) (cout<<#p<<endl);
int main()
{
    int para3 = 3;
    int para2 = 2;
    test(2);    //<==>cout<<para2<<endl;
    test(3);    //<==>cout<<para3<<endl;

    test2(test)        //<==>cout<<"test"<<endl;
    test2("test2");    //<==>cout<<""test2""<<endl;
    system("pause");
    return 0;
}