sah*_*dar 0 c linux gcc compiler-errors
//example1
#include<stdio.h>
int main()
{
printf("hello World"
);
}
//example2
#include<stdio.h>
int main()
{
printf("hello World
");
}
Run Code Online (Sandbox Code Playgroud)
在示例1中,编译器未显示任何错误,但是在示例2中,编译器显示了missing terminating " character错误。为什么?
C字符串文字不能包含文字换行符。这是C18标准,突出了相关部分。
6.4.5字符串文字
句法
Run Code Online (Sandbox Code Playgroud)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");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
74 次 |
| 最近记录: |