stl之map
https://blog.csdn.net/shuzfan/article/details/53115922
stl之unordered_map
https://blog.csdn.net/hk2291976/article/details/51037095
https://blog.csdn.net/jingyi130705008/article/details/82633778
int main()
{
//map<string, int> dict;
//map<string, int>::iterator iter;
unordered_map<string, int> dict;
unordered_map<string, int>::iterator iter;
// 插入数据的三种方式
dict["apple"] = 1;
dict.insert(pair<string,int>("banana",2));
dict.insert(map<string, int>::value_type("orange",3));
dict["orange"] = 4; // 有键值会修改,没有键值会插入。
dict.insert(map<string, int>::value_type("orange",5)); // 有键值不操作,没键值会插入。
cout << dict["lemon"] << endl; // 只要运行[],即便不赋值,也会插入一个默认值0
cout << dict.count("lemon") << endl; // 输出0
dict.empty() ?
cout << "no elment " << endl :
cout << "have " << dict.size() << " element" << endl;
// 遍历方法
for(iter = dict.begin(); iter != dict.end(); iter++) {
cout << iter->first << " " << iter->second << endl;
}
for(auto e : dict) {
cout << e.first <<" " << e.second <<endl;
}
// 查找方法
(iter = dict.find("banana")) != dict.end() ?
cout << "banana value is " << iter->second <<endl :
cout << "banana dost not exists" << endl;
dict.count("watermelon") == 0 ? // 返回键值等于key的元素的个数
cout << "watermelon dost not exists" << endl:
cout << "watermelon exists" << endl;
}
vector
https://blog.csdn.net/weixin_33692284/article/details/93203743?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&dist_request_id=&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control
https://blog.csdn.net/wang13342322203/article/details/94323165
std::vector<int> values (20); // 20个0
std::vector<int> values (20, 1); // 20个1
std::vector<int> values {20}; // 1个20
std::vector<int> values {20, 30}; // 1个20,一个30
std::array<std :: string, 5> words {"one", "two","three", "four", "five"};
std::vector<std::string> words_copy {std::begin(words) , std::end(words)};
返回一维空数组
return vector<int>();
返回二维空数组
vector<<vector<int>> ();
二维数组初始化
vector<vector<int>> vv (len, vector<int> (2, 0));