使用“和",“或"可以吗?等等,而不是“&&","||"? [英] Is it okay to use "and", "or" etc. instead of "&&", "||"?

查看:142
本文介绍了使用“和",“或"可以吗?等等,而不是“&&","||"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯于C ++中的andor关键字.我一直使用它们,输入它们对我来说既快速又舒适.听说这些别名是非标准的,可能不适用于所有编译器.但是我不确定,我真的不知道这是不是真的.
假设我给我我的代码,他在编译时会遇到问题吗?
使用andor而不是&&||可以吗?还是这些关键字真的是非标准的?
我使用MinGW编译器.

I'm used to the and and or keywords in C++. I've always used them and typing them is fast and comfortable for me. Once I've heard that these aliases are non-standard and may not work on all compilers. But I'm not sure of it, I don't really know if it's true.
Let's assume that I give someone my code, will he have problems compiling it?
Is it all right when I use and, or instead of &&, ||? Or are these keywords really non-standard?
P.S.I use the MinGW compiler.

推荐答案

事实上,它们是C ++中的标准,由ISO 14882:2003 C ++标准2.5/2定义(实际上,也就是1998年版的C ++标准所定义)标准).请注意,它们是语言本身内置的,不需要您包含某种头文件.

They are in fact standard in C++, as defined by the ISO 14882:2003 C++ standard 2.5/2 (and, indeed, as defined by the 1998 edition of the standard). Note that they are built into the language itself and don't require that you include a header file of some sort.

但是,它们很少使用,而且我还没有看到实际使用替代令牌的生产代码.首先出现替代令牌的唯一原因是,某些键盘上的这些字符(尤其是非QWERTY键盘)不存在或键入起来很笨拙.它仍然是向后兼容的标准.

However, they are very rarely used, and I have yet to see production code that actually uses the alternative tokens. The only reason why the alternative tokens exist in the first place is because these characters on some keyboards (especially non-QWERTY ones) were either nonexistent or clumsy to type. It's still in the standard for backwards compatibility.

即使它们是标准的,我也强烈建议您不要使用它们.替代令牌需要输入更多的字符,并且QWERTY键盘布局已经具有键入C ++代码所需的所有字符,而不必使用替代令牌.而且,它们很可能会使您的代码的读者感到困惑.

Even though they are standard, I highly recommend that you don't use them. The alternative tokens require more characters to type, and the QWERTY keyboard layout already has all the characters needed to type out C++ code without having to use the alternative tokens. Also, they would most likely bewilder readers of your code.

2.5/2替代令牌

在语言的各个方面,每个 替代令牌的行为相同, 分别作为其主要令牌, 除了其拼写.一套 表中定义了替代令牌 2.

In all respects of the language, each alternative token behaves the same, respectively, as its primary token, except for its spelling. The set of alternative tokens is defined in Table 2.

Table 2 - alternative tokens
+--------------+-----------+
| Alternative  |  Primary  |
+--------------+-----------+
|    <%        |    {      |
|    %>        |    }      |
|    <:        |    [      |
|    :>        |    ]      |
|    %:        |    #      |
|    %:%:      |    ##     |
|    and       |    &&     |
|    bitor     |    |      |
|    or        |    ||     |
|    xor       |    ^      |
|    compl     |    ~      |
|    bitand    |    &      |
|    and_eq    |    &=     |
|    or_eq     |    |=     |
|    xor_eq    |    ^=     |
|    not       |    !      |
|    not_eq    |    !=     |
+--------------+-----------+

这篇关于使用“和",“或"可以吗?等等,而不是“&amp;&amp;","||"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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