給定一個編譯時常量整數(一個對象,而不是一個宏),我可以在編譯時將它與字符串文字結合起來,可能與預處理器?組合字符串文字和整數常量
例如,我可以通過把它們彼此相鄰的串聯字符串文字:
bool do_stuff(std::string s);
//...
do_stuff("This error code is ridiculously long so I am going to split it onto "
"two lines!");
太好了!但是,如果我添加整型常量的組合:
const unsigned int BAD_EOF = 1;
const unsigned int BAD_FORMAT = 2;
const unsigned int FILE_END = 3;
是否有可能使用預處理與字符串文字莫名其妙地拼接呢?
do_stuff("My error code is #" BAD_EOF "! I encountered an unexpected EOF!\n"
"This error code is ridiculously long so I am going to split it onto "
"three lines!");
如果這是不可能的,我可以混合常量字符串與字符串文字?即如果我的錯誤代碼是字符串,而不是無符號的?
如果兩者都不可能,那麼將這些字符串文字和數字錯誤代碼混合在一起的最短,最乾淨的方法是什麼?
啊,是的。這個雙重宏觀很重要。在我的例子中我忘了一些東西。不錯的演出。 – JoshD 2010-10-04 23:51:21
爲什麼雙重宏? – Chubsdad 2010-10-05 00:05:47
@Chubsdad:http://codepad.org/DiAC35hl – 2010-10-05 00:09:10