// 变量与常量
int x{5}; // 花括号初始化
auto y = 3.14; // 类型推断
const int Z{100}; // 不可变
constexpr int SQ(int n) { return n*n; } // 编译期函数
// 流程控制
if (cond) {} else {}
if (auto v = f(); v > 0) {} // C++17 带初始化 if
switch (n) { case 1: ... break; default: ... }
for (int i = 0; i < n; ++i) {}
for (auto& e : vec) {} // 范围 for(改元素加 &)
while (cond) {}
do {} while (cond);
// 函数与 lambda
int add(int a, int b) { return a + b; }
void f(const std::string& s) {} // 大对象传 const&
auto f = [cap](Params) -> Ret { ... }; // lambda
// 类
class X {
public:
X(int v) : v_{v} {} // 构造函数 + 初始化列表
~X() {} // 析构
virtual void f() {} // 虚函数
private:
int v_{};
};
struct P { int x, y; }; // 纯数据用 struct
int 4 字节整数 double 8 字节浮点(默认)
unsigned 非负整数 bool 真/假
long/long long 大整数 char 1 字节字符/小整数
float 4 字节浮点(少用)void 无类型
std::string 字符串(自动管理内存)
std::string_view [17] 零拷贝字符串视图
std::vector<T> 动态数组(默认容器)
std::array<T,N> 固定大小数组
std::map<K,V> 有序字典 std::unordered_map 哈希字典
std::set<T> 有序集合 std::unordered_set 哈希集合
std::pair<A,B> 两个值 std::tuple<A,B,C> 多个值
std::optional<T> [17] 可能有值
std::variant<...> [17] 多类型之一
std::expected<T,E> [23] 有值或有错误
std::span<T> [20] 数组视图
std::unique_ptr<T> 独占所有权智能指针
std::shared_ptr<T> 共享所有权智能指针
<print> println / print(C++23)
<iostream> cin / cout(老式 IO)
<string> std::string
<vector> <map> <set> <unordered_map> <list> <deque> <array>
<algorithm> 排序查找等算法
<ranges> [20] 视图与 ranges 算法
<numeric> 求和 fold 等
<memory> 智能指针
<optional> <variant> <any> [17]
<expected> [23]
<span> [20]
<filesystem> [17] 文件系统
<chrono> 时间日期
<thread> <mutex> <atomic> 并发
<stdexcept> 异常类型
<type_traits> 编译期类型判断
<concepts> [20]
<cstdint> int64_t 等定宽整数
<cctype> isalpha 等字符判断
sort / ranges::sort 排序
find / find_if 查找
count / count_if 计数
max_element / min_element 极值
all_of / any_of / none_of 判断
accumulate 求和汇总(fold_left 见 C++23 节)
transform / views::transform 映射
reverse 反转
unique(先排序) 去重
remove_if + erase 删除
iota 生成连续整数
binary_search 二分查找(有序容器)
C++98 (1998)类、模板、STL 成型;string 等
C++11 (2011)auto、lambda、智能指针、移动语义、
范围 for、nullptr、constexpr、花括号初始化
★ 现代 C++ 的起点,本书默认你知道
C++14 (2014)泛型 lambda、返回类型推断
C++17 (2017)结构化绑定、optional/variant/any、
if constexpr、filesystem、string_view、
折叠表达式、inline 变量、if 初始化
★ 本书最低要求版本
C++20 (2020)concepts、ranges、三路比较、协程、
module、span、chrono 升级、format
C++23 (2023)print/println、expected、flat_map、
mdspan、fold、zip/enumerate、deducing this
C++26 (2026)进一步补全(你编译器的默认未来标准)
一句话:C++11 是分水岭;C++17 之后的新代码写法 和 90 年代的老 C++ 完全是两种语言。