
這些鮮為人知的C++符号,可直接在代碼中使用,但實踐中不推薦這麼做,可作為茶餘飯後的樂趣了解C++的另一面。
雖然它們鮮為人知,但卻不是GNU g++獨有的,而是C++标準定義的,找一本C++标準書或pdf文檔看看,就可以見到它們赫然在目。
代碼中,可用左邊的替代右邊的:
<b>可選的符号</b>
<b>可替代的常見符号</b>
<b> </b>
{
注意不能替代函數定義的{
%>
}
注意不能替代函數定義的}
<:>
[
:>
]
%:
#
%:%:
##
and
&&
or
||
xor
^
bitor
|
compl
~
bitand
&
and_eq
&=
or_eq
|=
xor_eq
^=
not
!
not_eq
!=
// GNU g++編譯方法:g++ -g -o a a.cpp
#include
int main()
int N = 2;
for (int i=0; i
<b></b>
printf("%d\n", i);
<b>%></b>
return 0;
三個字元等同單個字元,GNU g++編譯時需要指定編譯參數“<b>-trigraphs</b>”。
??=
??/
\
??’
??(
??)
??
??>
??!
??-
// 注意使用GNU g++編譯以下代碼,需要指定編譯參數“<b>-trigraphs</b>”
// g++ -g -o b b.cpp <b>-trigraphs</b>
// 下一語句完全等同于:#define
index(array, i) array[i]
<b>??=</b>define index(array, i) array<b>??(</b>i<b>??)</b>
int m[] = { 3, 7 };
printf("m[0]=%d,
m[1]=%d\n", index(m, 0), index(m, 1));
asm
do
if
return
typedef
auto
double
inline
short
typeid
bool
dynamic_cast
int
signed
typename
break
else
long
sizeof
union
case
enum
mutable
static
unsigned
catch
explicit
namespace
static_cast
using
char
export
new
struct
virtual
class
extern
operator
switch
void
const
false
private
template
volatile
const_cast
float
protected
this
wchar_t
continue
for
public
throw
while
default
friend
register
true