宏中的#与##

#:链接字符串,字符串常量需要加“”号;#的右边不能加字符串常量。

##:粘合参数,不仅仅是字符串,可以是其他类型。

#include<iostream>
#define STR(s) "hello"#s#s
#define CONS(a,b)(int)(a##e##b)

int main() {
    std::cout << STR((vck)) << std::endl;
    std::cout << CONS(2, 3)<<std::endl;
    std::cout << (int)(2e3);
    return 0;
}

 

posted @ 2020-06-16 10:05  每天都要吃早饭  阅读(266)  评论(0编辑  收藏  举报