Skip to content

Commit

Permalink
Merge pull request #5 from kwongtailau/master
Browse files Browse the repository at this point in the history
Fix some misspells
  • Loading branch information
linw7 authored May 30, 2018
2 parents 03bbdc5 + eeaa4c9 commit fce0ff7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions 编程语言C++.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,22 +450,24 @@ STL内容虽然看起来很多,单独成书都不是问题(《STL源码剖
用法:

定义:
mao<T_key, T_value> map;
map<T_key, T_value> mymap;

插入元素:
map.insert(pair<T_key, T_value>(key, value)); // 同key不插入
map.insert(map<T_key, T_value>::value_type(key, value)); // 同key不插入
map[key] = value; // 同key覆盖
mymap.insert(pair<T_key, T_value>(key, value)); // 同key不插入
mymap.insert(map<T_key, T_value>::value_type(key, value)); // 同key不插入
mymap[key] = value; // 同key覆盖

删除元素:
map.erase(key); // 按值删
map.erase(iterator); // 按迭代器删
mymap.erase(key); // 按值删
mymap.erase(iterator); // 按迭代器删

修改元素:
map[key] = new_value;
mymap[key] = new_value;

遍历容器:
for(auto it = vec.begin(); it != vec.end(); ++it) {......}
for(auto it = mymap.begin(); it != mymap.end(); ++it) {
cout << it->first << " => " << it->second << '\n';
}

实现:

Expand Down

0 comments on commit fce0ff7

Please sign in to comment.