std::print & std::format (C++23)
Modern formatting and printing with Python-style format strings
Overview
C++23 introduces std::print and std::format for modern, type-safe string formatting. This provides a faster and safer alternative to iostreams and printf.
#include <print>
#include <format>
// Type-safe formatting
std::string s = std::format("Hello, {}!", "World");
// Direct printing
std::print("Value: {}
", 42);
// Format specifiers
std::print("Pi = {:.2f}
", 3.14159); // Pi = 3.14Benefits
- ✓Type-safe at compile time
- ✓Faster than iostreams
- ✓Python-style format strings