相关疑难解决方法(0)

C/C++宏字符串连接

#define STR1      "s"
#define STR2      "1"
#define STR3      STR1 ## STR2
Run Code Online (Sandbox Code Playgroud)

是否有可能连接STR3 =="s1"?您可以通过将args传递给另一个宏函数来完成此操作.但是有直接的方法吗?

c c++ c-preprocessor

105
推荐指数
3
解决办法
17万
查看次数

如何将 #define 的精确文字存储在字符串中以进行打印

#define图书馆深处有一个宏,我想快速知道它的确切值。有没有办法将定义的值存储到字符串中以便我可以打印它?

#define intgr 12
#define bnry 0b00000001
#define hex 0x0A
#define str "Hello World"

String myStr;

myStr = intgr;
cout<< myStr << endl;  //Simple enough, work no problem
//12              <- actual
//12              <- expected

myStr = bnry; // using "bnry" would not work as #define does not touch inside quotes
cout<< myStr << endl;
//1               <- actual
//0b00000001      <- expected

myStr = hex;
cout<< myStr << endl;
//10               <- actual
//0x0A             <- expected

myStr = str;
cout<< myStr << …
Run Code Online (Sandbox Code Playgroud)

c-preprocessor

0
推荐指数
1
解决办法
103
查看次数

标签 统计

c-preprocessor ×2

c ×1

c++ ×1