[問題] Macro 要如何擷字串
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
gcc
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
要如何透過macro擷取字串出來. 這有點難解釋我用底下的sample code來解釋.
餵入的資料(Input):
預期的正確結果(Expected Output):
底下的code, 會輸出 enum_my_int 得字串,
想請問要如何做, 在macro的操作下, 可以把enum_ 移除.
只留下,想要的my_int
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
4 typedef int my_int;
5 typedef double my_double;
6
7 typedef enum
8 {
9 enum_my_int,
10 enum_my_double,
11 } enum_type;
12
13 #define macro_test_str(p) #p
14
15 void main(void)
16 {
17
18 printf("%s\n", macro_test_str(enum_my_int));
19
20 }
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.231.105.117
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1443921393.A.045.html
推
10/04 09:55, , 1F
10/04 09:55, 1F
→
10/04 09:56, , 2F
10/04 09:56, 2F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章
-3
16