Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

UTF-8 character literals

Use case

Explicit UTF-8 encoding.

Explanation

u8'x' creates a UTF-8 encoded character literal.

Code

#include <iostream>

int main() {
  char c = u8'X';
  std::cout << "Char: " << c << "\n";
  return 0;
}

View on GitHub.

Output

$ ./src/c++17/build/utf-8-character-literals
Char: X