C++写“或”而不是||

发布于 2024-11-07 11:16:57 字数 490 浏览 0 评论 0原文

可能的重复:
C++ 替代令牌?

我正在和我的一个朋友一起完成 C++ 作业,我们'一直在他的计算机/环境(带有 Eclipse 的 Macbook Pro)上进行大量编码。在一些代码中,他使用 andor 而不是 &&|| 编写条件。该代码在他的计算机上编译得很好,但当我尝试在家里的计算机(装有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

你对谁都笑 2024-11-14 11:16:57

有一些“替代表示”:andand_eqbitandbitorcomplnot_eqor_eqxor、和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, and xor_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.

烟凡古楼 2024-11-14 11:16:57

它们被称为运算符同义词,它们是显然是标准的一部分,但我不确定它们的支持范围有多大。

They're called operator synonyms, and they're apparently part of the standard, but I'm not sure how widely supported they are.

远昼 2024-11-14 11:16:57

您可以将 define 添加到顶部来绕过它吗?

#define and &&
#define or ||

Could you add defines to the top to get around it?

#define and &&
#define or ||
城歌 2024-11-14 11:16:57

它是由编译器扩展或源代码中其他位置的 #define 引起的,可能来自 iso646.h defineing or||and&&。您可能还会看到类似使用 not 代替 ! 的情况。

如果它是编译器扩展,并且您希望避免将所有 orand 更改为 ||&&,只需在顶部添加一些您自己的#define

#define or ||
#define and &&

It is either caused by a compiler extension or a #define somewhere else in the source code, possibly from iso646.h defineing or to be || and and to be &&. You might also see something like using not 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 and and to || and &&, simply add some #defines of your own at the top:

#define or ||
#define and &&
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文