gpt4 book ai didi

c - 字符串化运算符

转载 作者:太空宇宙 更新时间:2023-11-04 05:29:45 24 4
gpt4 key购买 nike

下面的代码如何正确编译,

#include <stdio.h>
#define stringer( x ) printf_s( #x "\n" )
int main() {
stringer( "In quotes when printed to the screen" );
}

难道它不应该扩展成

printf_s(""In quotes when printed to the screen""\n");

这是一个错误,因为 printf_s 中有嵌套的双引号??

最佳答案

不,# 运算符专门处理字符串文字。它必须 \ 转义传递给它的字符串文字中的每个 "。正确的扩展是:

printf_s( "\"In quotes when printed to the screen\"" "\n" );

关于c - 字符串化运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10676999/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com