前置知识: C++

C++格式化输出

00:00
1 min Intermediate 2026/6/14

std::format与格式化

1. std::format(C++20)

#include <format>

std::string s = std::format("Hello, {}!", "World");
std::string s2 = std::format("{0} + {1} = {2}", 1, 2, 3);
std::string s3 = std::format("{:.2f}", 3.14159); // "3.14"
std::string s4 = std::format("{:10d}", 42);      // "        42"

2. std::print(C++23)

#include <print>

std::print("Hello, {}!\n", "World");
std::println("Value: {}", 42);

知识检测

学习进度

-- 已学文档
--% 知识覆盖率

学习推荐

专注模式