fix(cpp). update hash_map (#800)

* fix(cpp). update hash_map

遍历 map 还是 k-v 键值对

* Update hash_map.md

---------

Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
Flamingo 2023-09-26 11:07:14 +08:00 committed by GitHub
parent ea7eb514fc
commit 22be495412
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View file

@ -39,13 +39,13 @@ int main() {
} }
cout << "\n单独遍历键 Key" << endl; cout << "\n单独遍历键 Key" << endl;
for (auto key : map) { for (auto kv : map) {
cout << key.first << endl; cout << kv.first << endl;
} }
cout << "\n单独遍历值 Value" << endl; cout << "\n单独遍历值 Value" << endl;
for (auto val : map) { for (auto kv : map) {
cout << val.second << endl; cout << kv.second << endl;
} }
return 0; return 0;

View file

@ -299,12 +299,12 @@
cout << kv.first << " -> " << kv.second << endl; cout << kv.first << " -> " << kv.second << endl;
} }
// 单独遍历键 key // 单独遍历键 key
for (auto key: map) { for (auto kv: map) {
cout << key.first << endl; cout << kv.first << endl;
} }
// 单独遍历值 value // 单独遍历值 value
for (auto val: map) { for (auto kv: map) {
cout << val.second << endl; cout << kv.second << endl;
} }
``` ```