c#无效的转义序列
Sometimes, while writing Escape Sequences in C program, we mistakenly typed an invalid escape sequence, which does not give any error but does not give the expected result.
有时,在用C程序编写Escape序列时,我们错误地键入了一个无效的 Escape 序列 ,它不会产生任何错误,但不能给出预期的结果。
For example, if we want to print a "new line" between two words in a text and mistakenly typed \m instead of \n.
例如,如果我们要在文本中的两个单词之间打印“换行” ,并错误地键入\ m而不是\ n 。
Consider the program:
考虑该程序:
#include <stdio.h>
int main(void) {
printf("Hello world\mHow are you?");
return 0;
}
Output
输出量
Hello worldmHow are you?
We wanted to print "Hello world" and "How are you?" in separate lines but there is an invalid escape sequence \m. Thus, the result is "Hello worldmHow are you?".
我们想打印“ Hello world”和“你好吗?” 在单独的行中,但是存在无效的转义序列\ m 。 因此,结果是“ Hello worldm,你好吗?” 。
如何修复“ C中无效的转义序列”错误 (How to fix "Invalid escape sequence in C" error)
To fix this and such errors, you should know about all escape sequences and use them properly.
要解决此错误和此类错误,您应该了解所有转义序列并正确使用它们。
Read: Escape sequences in C
阅读: C语言中的转义序列
Correct code
正确的代码
#include <stdio.h>
int main(void) {
printf("Hello world\nHow are you?");
return 0;
}
Output
输出量
Hello world
How are you?
翻译自: https://www.includehelp.com/c-programs/invalid-escape-sequence-in-c.aspx
c#无效的转义序列