C++ 转义字符文字中的撇号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2414478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:24:54  来源:igfitidea点击:

Escaping an apostrophe in a character literal

c++escaping

提问by boddhisattva

Could you please tell me how can one escape an apostrophe.

你能告诉我如何摆脱撇号吗?

I need it to process non apostrophe characters through file operations so when I encounter an apostrophe(') I can't just give ch!='''. It doesn't work. Could you please tell me the right format. Thank you..:)

我需要它通过文件操作处理非撇号字符,所以当我遇到撇号(')时,我不能只给ch!='''. 它不起作用。你能告诉我正确的格式吗?谢谢..:)

回答by raj

Use \', for example:

使用\',例如:

if ( ch != '\'' )

\'is an escape sequence for the apostrophe.

\'是撇号的转义序列。

Google for "escape sequence" to know more about it.

谷歌搜索“转义序列”以了解更多信息。

回答by Daniel LeCheminant

You can escapea single quote as

您可以将单引号转义

'\''

for example

例如

while(*p && *p != '\'') p++;

This is an escape sequence; the backslash tells the compiler that following 'normal character, and not as one of the single quotes that you surround a character with.

这是一个转义序列;反斜杠告诉编译器跟随'正常字符,而不是作为将字符括起来的单引号之一。