现在的位置: 首页 > 综合 > 正文

c++宏定义系列1

2013年05月05日 ⁄ 综合 ⁄ 共 379字 ⁄ 字号 评论关闭

[c/c++]宏定义,#,##
# —— 字符串
##——连接两个参数
#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;
}

抱歉!评论已关闭.