给定一个编译时常量整数(一个对象,而不是一个宏),我可以在编译时将它与字符串文字结合起来,可能与预处理器?组合字符串文字和整数常量
例如,我可以通过把它们彼此相邻的串联字符串文字:
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