C++一些宏定义

来源:互联网 发布:b站小学生知乎 编辑:程序博客网 时间:2024/06/06 09:51
#include <iostream>#define PI 3.1415926 //#define <宏名> <字符串>#define MIN(X, Y) (X) < (Y) ? (X) : (Y) //#define <宏名>(<参数表>) <宏体>#define Conn(X, Y) X##Y //简单的把x和y连接起来,但不处理。即Conn(a, 2)--->a2, 编译的时候,如果没有a2就会报错。//#define TOCHAR(X) #@X 不可以这样使用#define TOSTRING(X) #X //将X变成字符串using namespace std;int main(){    double d = 1.0;    cout << Conn(1, 2) << endl;//    cout << Conn(a, 2) << endl; //编译报错,a2 not declare    char *str = TOSTRING();    cout << str << endl;    return 0;}

0 0