0

为什么\a(哔声),\v(垂直选项卡)在我的程序中不起作用,即使根据下面的链接它们是标准的?为什么即使不使用单引号也可以工作\'?最后,\?正如微软网站所说的那样,它完全是一个转义字符,因为我使用? printf()格式字符串中的符号没有\,它工作正常。

说清楚:

  • 为什么不\a工作\v

  • 为什么单引号可以在没有转义序列的情况\下工作?\'

  • \?转义序列吗?(链接这么说但是?没有 ? 工作\

http://msdn.microsoft.com/en-us/library/h21280bw(v=vs.80).aspx http://en.wikipedia.org/wiki/Escape_sequences_in_C

4

2 回答 2

2
  • Why are \a and \v not working?

Because the console you’re using doesn’t support them. The compiler does, and produces the correct character code in the output, but the terminal emulator ignores them.

  • Why single quote works without the \ even though \' is an escape sequence?

Because it’s unnecessary to escape it in strings, you only need to escape it in a char literal. Same for \" for string literal:

  • "'" vs. '\''
  • '"' vs. "\""
  • Is \? an escape sequence? (The link says so but ? works without the \)

The link actually says something different:

Note that … \? specifies a literal question mark in cases where the character sequence would be misinterpreted as a trigraph

It’s only there to avoid ambiguity in cases where the following characters would form a valid trigraph, such as ??= (which is the trigraph for #). If you want to use this sequence in a string, you need to escape the first (or second) ?.

于 2013-05-18T13:22:21.427 回答
0

一些转义序列是特定于设备的。因此它们不会在每个设备上产生所需的效果。例如,垂直制表符 ( \v) 和换页 ( \f) 转义序列不会影响屏幕输出。但它们确实执行适当的打印机操作。

于 2013-05-18T13:30:51.043 回答