mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 04:31:55 +08:00
Add C++ iterator example for C++ (#837)
* 增加c++迭代器访问示例 * Update hash_map.md * Update hash_map.cpp --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user