📚 C++ 学习

8. 现代 C++ 新特性

auto 类型推导

auto x = 42;           // int
auto s = string("hi");  // string
auto it = v.begin();   // 迭代器类型自动推导

范围 for 循环

vector<int> v = {1,2,3};
for (auto& n : v) {
    cout << n;
}

Lambda 表达式

sort(v.begin(), v.end(), [](int a, int b) {
    return a > b;   // 降序
});

移动语义

std::move 避免不必要的深拷贝,大幅提升性能。现代 C++ 核心是:用 STL、用智能指针、用 auto、用 lambda。