統(tǒng)一樣式的初始化
int arr[] {1,2,3}; //沒有等號
vector<int> vi{1,2,3};
map<int, string> m{ {1,"a"}, {2, "b"} };
string str{"hello"};
int *p = new int[20]{1,2,3};
struct A {
int i,j;
A(int m, int n):i(m), j(n) {}
};
A func(int m, int n){return {m,n};}
A *p = new A{3,7};
成員變量默認初始值
class B{
public:
int m = 123;
int n;
}
auto 關(guān)鍵字
auto a = 100; // a 為 int
auto p = new A(); // p 是 A *
auto k = 23LL; // k為long long
decltype求表達式類型
int i;
double d;
decltype(i) c; // c為 int類型
decltype(d) f; // f為 double類型
智能指針 shard_ptr
需要include<memory>
見圖片
空指針 nullptr
見圖三
基于范圍的for循環(huán)
無序map啃奴, 哈希表
需要include<unordered_map>
正則表達式
需要引入 include<regex>
labmda 表達式
強制類型轉(zhuǎn)換
static_cast, const_cast, interpret_cast, dynamic_cast
try-catch異常處理
try{
if(..)throw -1;
else if () throw 1.0
}
catch(int i){
}
catch(double d){
}
catch(...){
// 捕獲其他異常几晤, ... 統(tǒng)配
}