Skip to content

Last updated:2026-10-12

C++ Trigraphs

C++那些事: Removing Trigraphs

Before C++17, trigraphs were a facility for writing programs with small character codes such as ISO/IEC 646, introduced in C89. ISO/IEC 646 lacks the following characters used in C, so ?? is used to escape them as follows:

Trigraph Replacement
??= #
??( [
??) ]
??< {
??> }
??/ \
??! |
??- ~
??' ^

\? is escaped to prevent it from being replaced by the trigraph table.

Trigraphs were removed in C++17, and ??= and the like are no longer replaced.

Example

Before C++17:

std::cout << "??=" << std::endl;
std::cout << "??(" << std::endl;
std::cout << "?\?(" << std::endl;

Output:

#
[
??(

C++17 and later:

??=
??(
??(

Nowadays, presumably because character encodings such as Unicode are ubiquitous, trigraphs are no longer needed, and compilers such as gcc disable them by default.

Comments