某人在学术版发表帖子,让我想起了读老版本的 C++ 教程时读到的内容:
以前的计算机键盘上很可能没有很多符号,因此 C/C++ 使用了其他的内容,让你可以轻松打入这些符号:
替换表:(C 语言需要包含 iso646.h 头文件,C++ 可以直接使用)
| 新符号 | 等效的原符号 |
|---|---|
<% | { |
%> | } |
<: | [ |
:> | ] |
bitand | & |
bitor | ` |
xor | ^ |
compl | ~ |
and | && |
or | ` |
and_eq | &= |
or_eq | ` |
xor_eq | ^= |
意思就是说,你可以将下面的程序:
// 原写法
#include <iostream>
int main() {
int a, b;
std::cin >> a >> b;
bool res = ((a ^ b) == (a & b)) || ((~a) == (~b));
std::cout << res << std::endl;
return 0;
}
替换成:
// 替换写法
#include <iostream>
int main() <%
int a, b;
std::cin >> a >> b;
bool res = ((a xor b) == (a bitand b)) or ((compl a) == (compl b));
std::cout << res << std::endl;
return 0;
%>
而且大概率可以通过编译。