A few characters have an alternative representation, called a trigraph sequence. A trigraph is a three-character sequence that represents a single character. The sequence always starts with two question marks. The third character determines which character the sequence represents. All the trigraph sequences are shown in Table 1-3. If the third character is not one of those in the table, the sequence is not a trigraph and is left alone. For example, the characters ???- represent the two characters ?~. Note that trigraphs are expanded anywhere they appear, including within string literals and character literals, in comments, and in preprocessor directives.
Trigraph |
Replacement |
---|---|
??= |
# |
??/ |
\ |
??' |
^ |
??( |
[ |
??) |
] |
??! |
| |
??< |
{ |
??> |
} |
??- |
~ |
Not all compilers support trigraphs. Some compilers require an extra switch or option. Others use a separate program to convert all trigraphs to their equivalent characters.
Do not use trigraphs. They are confusing to read and use. If you ever write multiple, adjacent question marks, make sure you are not accidentally writing a trigraph. For example:
std::cout << "What do you mean??!!\n";
To avoid the trigraph interpretation, separate the string literal:
std::cout << "What do you mean?" "?!!\n";
or escape the question marks:
std::cout << "What do you mean\?\?!!\n";