c - 为什么我缺少终止“字符?
问题描述
//example1
#include<stdio.h>
int main()
{
printf("hello World"
);
}
//example2
#include<stdio.h>
int main()
{
printf("hello World
");
}
在示例 1 中,编译器没有显示任何错误,但在示例 2 中,它显示了missing terminating " character
错误。为什么?
解决方案
C 字符串文字不能包含文字换行符。这是突出显示相关部分的C18标准。
6.4.5 字符串文字
句法
string-literal: encoding-prefixopt " s-char-sequenceopt " s-char-sequence: s-char s-char-sequence s-char s-char: any member of the source character set except the double-quote ", backslash \, or new-line character <---- HERE escape-sequence
如果您希望字符串文字包含换行符,请\n
改用,例如"hello\nworld"
.
如果您希望将字符串文字分成多行,请使用多个字符串文字:
printf("hello "
"world");
推荐阅读
- merge - Gulp 4 ReferenceError:未定义合并
- express - 如何在 twilio mms 中设置标题
- shopify - 可以从自定义前端应用程序使用 shopify 3rd 方应用程序吗?
- pine-script - 如何创建一条简单的黑线来连接烛体的低点和高点?[松稿]
- java - 如何在调用 Async 方法中使用 @Async 注释服务方法?弹簧靴
- linux - 我正在尝试配置 I3status 并且我的内存条显示的内存比 /proc/meminfo 中的实际内存多得多?
- complexity-theory - 问题可以在 NP 中而不是 NP-Complete 或 P 中吗?
- indexing - Python中的SUMIF MATCH条件
- c# - 计时器归零后重新启用按钮
- python - 覆盖tkinter中标签的内存