C++写“或”而不是||
可能的重复:
C++ 替代令牌?
我正在和我的一个朋友一起完成 C++ 作业,我们'一直在他的计算机/环境(带有 Eclipse 的 Macbook Pro)上进行大量编码。在一些代码中,他使用 and
和 or
而不是 &&
和 ||
编写条件。该代码在他的计算机上编译得很好,但当我尝试在家里的计算机(装有 Visual Studio 2010 的 PC)上编译它时,我收到编译器错误并被迫切换它们。我的朋友还证明这种语法可以在 Linux 环境中使用 emacs/g++ 运行。
我以前从未见过这种事情。这是否被广泛使用或被大多数编译器支持?
Possible Duplicate:
C++ alternative tokens?
I'm working on an assignment in C++ with a friend of mine, and we've been doing lots of the coding on his computer/environment (a Macbook Pro with Eclipse). In some of the code he has written conditions using and
and or
rather than &&
and ||
. The code compiles just fine on his computer, but when I try and compile it on my computer at home (a PC with Visual Studio 2010) I get compiler errors and am forced to switch them. My friend also attests that this syntax has worked using emacs/g++ in a Linux environment.
I had never seen this type of thing before. Is this used widely or supported by most compilers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有一些“替代表示”:
and
、and_eq
、bitand
、bitor
、compl
、非
、not_eq
、或
、or_eq
、xor
、和xor_eq。它们是 C++ 的标准语言功能。如果使用
/Za
(标准一致性模式)标志进行编译,Visual C++ 仅支持这些关键字作为关键字。There are a handful of "alternative representations":
and
,and_eq
,bitand
,bitor
,compl
,not
,not_eq
,or
,or_eq
,xor
, andxor_eq
. They are a standard language feature of C++.Visual C++ only supports these as keywords if you compile with the
/Za
(standards conformance mode) flag.#include
#include <iso646.h>
它们被称为运算符同义词,它们是显然是标准的一部分,但我不确定它们的支持范围有多大。
They're called operator synonyms, and they're apparently part of the standard, but I'm not sure how widely supported they are.
您可以将
define
添加到顶部来绕过它吗?Could you add
define
s to the top to get around it?它是由编译器扩展或源代码中其他位置的
#define
引起的,可能来自iso646.h
define
ingor
为||
,and
为&&
。您可能还会看到类似使用not
代替!
的情况。如果它是编译器扩展,并且您希望避免将所有
or
和and
更改为||
和&&
,只需在顶部添加一些您自己的#define
:It is either caused by a compiler extension or a
#define
somewhere else in the source code, possibly fromiso646.h
define
ingor
to be||
andand
to be&&
. You might also see something like usingnot
in place of!
as well.If it is a compiler extension and you want to avoid having to go through and change all the
or
andand
to||
and&&
, simply add some#define
s of your own at the top: