diff --git a/codes/cpp/chapter_hashing/hash_map.cpp b/codes/cpp/chapter_hashing/hash_map.cpp index 1f295ec7b..090c2eb10 100644 --- a/codes/cpp/chapter_hashing/hash_map.cpp +++ b/codes/cpp/chapter_hashing/hash_map.cpp @@ -39,13 +39,13 @@ int main() { } cout << "\n单独遍历键 Key" << endl; - for (auto key : map) { - cout << key.first << endl; + for (auto kv : map) { + cout << kv.first << endl; } cout << "\n单独遍历值 Value" << endl; - for (auto val : map) { - cout << val.second << endl; + for (auto kv : map) { + cout << kv.second << endl; } return 0; diff --git a/docs/chapter_hashing/hash_map.md b/docs/chapter_hashing/hash_map.md index 6d10503bd..63ee3e347 100755 --- a/docs/chapter_hashing/hash_map.md +++ b/docs/chapter_hashing/hash_map.md @@ -299,12 +299,12 @@ cout << kv.first << " -> " << kv.second << endl; } // 单独遍历键 key - for (auto key: map) { - cout << key.first << endl; + for (auto kv: map) { + cout << kv.first << endl; } // 单独遍历值 value - for (auto val: map) { - cout << val.second << endl; + for (auto kv: map) { + cout << kv.second << endl; } ```