Add C++ iterator example for C++ (#837)

* 增加c++迭代器访问示例

* Update hash_map.md

* Update hash_map.cpp

---------

Co-authored-by: Yudong Jin <krahets@163.com>
pull/888/head
52coder 1 year ago committed by GitHub
parent 2035aa0cf1
commit 436b6fa9a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -37,15 +37,9 @@ int main() {
for (auto kv : map) {
cout << kv.first << " -> " << kv.second << endl;
}
cout << "\n单独遍历键 Key" << endl;
for (auto kv : map) {
cout << kv.first << endl;
}
cout << "\n单独遍历值 Value" << endl;
for (auto kv : map) {
cout << kv.second << endl;
cout << "\n使用迭代器遍历 Key->Value" << endl;
for (auto iter = map.begin(); iter != map.end(); iter++) {
cout << iter->first << "->" << iter->second << endl;
}
return 0;

@ -298,13 +298,9 @@
for (auto kv: map) {
cout << kv.first << " -> " << kv.second << endl;
}
// 单独遍历键 key
for (auto kv: map) {
cout << kv.first << endl;
}
// 单独遍历值 value
for (auto kv: map) {
cout << kv.second << endl;
// 使用迭代器遍历 key->value
for (auto iter = map.begin(); iter != map.end(); iter++) {
cout << iter->first << "->" << iter->second << endl;
}
```

Loading…
Cancel
Save