字符串化运营 [英] Stringizing operator
本文介绍了字符串化运营的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何以下code编译正确,
How does the following code compile correctly,
#include <stdio.h>
#define stringer( x ) printf_s( #x "\n" )
int main() {
stringer( "In quotes when printed to the screen" );
}
是不是应该得到扩展成
isn't it supposed to get expanded into
printf_s(""In quotes when printed to the screen""\n");
这是一个错误,因为在printf_s嵌套双引号??
which is an error as there are nested double quotes in printf_s??
推荐答案
没有,在#
运营商处理字符串字面量特别。在一个字符串文字传递给它,它必须 \\
逃脱每个正确的扩展:
No, the #
operator handles character string literals specially. It must \
escape each "
in a character string literal that is passed to it. The correct expansion is:
printf_s( "\"In quotes when printed to the screen\"" "\n" );
这篇关于字符串化运营的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文