是否必须逃离制表字符C和C ++? [英] Is it mandatory to escape tabulator characters in C and C++?

查看:107
本文介绍了是否必须逃离制表字符C和C ++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C和C ++(和其他几种语言)的字符和字符串常量水平制表符(ASCII code 9)表示转义形式'\\ T'\\ t的。不过,我经常打字的字符串作为例如转义制表字符A	 B(没有在杠一TAB A B ),并且至少铛似乎++不要打扰 - 字符串似乎等同于A \\ TB。我喜欢的转义版本更好,因为长期缩进多行字符串在源$ C ​​$ C更好的可读性。

In C and C++ (and several other languages) horizontal tabulators (ASCII code 9) in character and string constants are denoted in escaped form as '\t' and "\t". However, I am regularly typing the unescaped tabulator character in string literals as for example in "A B" (there is a TAB in betreen A and B), and at least clang++ does not seem to bother - the string seems to be equivalent to "A\tB". I like the unescaped version better since long indented multi-line strings are better readable in the source code.

现在,我问自己,这是否是在C和C一般法律++或只是我的编译器的支持。便携性如何在字符和字符串常量转义制表?

Now I am asking myself whether this is generally legal in C and C++ or just supported by my compiler. How portable are unescaped tabulators in character and string constants?

令人惊讶的我找不到答案这个看似简单的问题,无论是与谷歌也没有对计算器(我刚刚发现的这个中隐约相关的问题)。

Surprisingly I could not find an answer to this seemingly simple question, neither with Google nor on stackoverflow (I just found this vaguely related question).

推荐答案

是的,您可以在一个字符串或字符,并至少根据C ++ 11制表符。允许的字符包括(与我的强调):

Yes, you can include a tab character in a string or character literal, at least according to C++11. The allowed characters include (with my emphasis):

除了在源代码字符集的任何成员
  双引号,反斜线 \\ ,或换行字符

any member of the source character set except the double-quote ", backslash \, or new-line character

(从 C ++ 11标准,附件A.2)

和源字符集包括:

空格字符,控制字符重新presenting 水平标签,垂直制表符,换页,以及新线,加上下面91图形字符

the space character, the control characters representing horizontal tab, vertical tab, form feed, and new-line, plus the following 91 graphical characters

(从 C ++ 11标准款2.3.1)

更新:我刚注意到你问两种不同的语言。对于C99来说,答案同样是肯定的。措辞不同,但基本上是说同样的事情:

UPDATE: I've just noticed that you're asking about two different languages. For C99, the answer is also yes. The wording is different, but basically says the same thing:

在字符常量或字符串,执行字符集的成员应当重新由相应的源代码字符集的成员psented $ P $ 或[...]

In a character constant or string literal, members of the execution character set shall be represented by corresponding members of the source character set or [...]

其中源和执行字符集包括

where both the source and execution character sets include

控制字符重新presenting 水平标签,垂直标签,
  换。

control characters representing horizontal tab, vertical tab, and form feed.

这篇关于是否必须逃离制表字符C和C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆