看板 C_and_CPP 關於我們 聯絡資訊
開發平台(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
LiloHuang: #define macro_test_str(p) #p + 5 // len(enum_) = 5 10/04 09:55
LiloHuang: 這不算是移除,只是前進幾個字元,macro 操作無法移除 10/04 09:56