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

std::print/std::println

Use case

Formatted output without << chaining.

Explanation

std::println = std::format + newline + stdout. Replaces verbose std::cout << ... << "\n chains.

Code

#include <cstdint>
#include <print>

int main() {
  uint64_t addr = 0x10001000;
  // $ echo "bl 0x40" | llvm-mc -triple=aarch64 -show-encoding
  // bl	#64                             // encoding: [0x10,0x00,0x00,0x94]
  uint32_t opcode = 0x94000010;
  // https://en.cppreference.com/w/cpp/utility/format/spec.html
  std::println("Entry point: {:#x}", addr);
  std::println("Opcode: {:#x} at {:#x}", opcode, addr);

  return 0;
}

View on GitHub.

Output

$ ./src/c++23/build/std-print-std-println
Entry point: 0x10001000
Opcode: 0x94000010 at 0x10001000