second.find(0)->second++; coutsecond.find(3)->second+=100; hash_-map::迭代器h5_-2; 对于(h5_itor2=h5.begin();h5_itor2!=h5.end();h5_itor2++) { hash_-map submap=h5_-2->second; hash_映射::迭代器子映射器; 对于(submap_itor=submap.begin();submap_itor!=submap.end();submap_itor++) { cout,c++,hashmap,nested,C++,Hashmap,Nested" /> second.find(0)->second++; coutsecond.find(3)->second+=100; hash_-map::迭代器h5_-2; 对于(h5_itor2=h5.begin();h5_itor2!=h5.end();h5_itor2++) { hash_-map submap=h5_-2->second; hash_映射::迭代器子映射器; 对于(submap_itor=submap.begin();submap_itor!=submap.end();submap_itor++) { cout,c++,hashmap,nested,C++,Hashmap,Nested" />

C++;好像和我预期的结果不一样 我的C++低,现在学习在STL使用哈什图。当我在以下玩具代码中测试嵌套哈希_映射时,它似乎可以工作: #include <hash_map> #include <iostream> using namespace std; int main() { cout<<"h4 h5"<<endl; hash_map<int,int&> h4; int temp=0; h4.insert(pair<int,int&>(0,temp)); hash_map<int, hash_map<int,int&>> h5; h5.insert(pair<int, hash_map<int,int&>>(1,h4)); hash_map<int, hash_map<int,int&>>::iterator h5_itor=h5.find(1); h5_itor->second.find(0)->second++; h5_itor->second.find(0)->second++; h5_itor->second.find(0)->second++; cout<<h5.find(1)->second.find(0)->second<<endl; int temp2=7; h5.find(1)->second.insert(pair<int,int&>(3,temp2)); h5.find(1)->second.find(3)->second+=100; hash_map<int, hash_map<int,int&>>::iterator h5_itor2; for(h5_itor2=h5.begin();h5_itor2!=h5.end();h5_itor2++) { hash_map<int,int&> submap=h5_itor2->second; hash_map<int,int&>::iterator submap_itor; for(submap_itor=submap.begin();submap_itor!=submap.end();submap_itor++) { cout<<submap_itor->first<<" -> "<<submap_itor->second<<endl; } } return 0; } #包括 #包括 使用名称空间std; int main() { coutsecond++; h5_itor->second.find(0)->second++; coutsecond.find(3)->second+=100; hash_-map::迭代器h5_-2; 对于(h5_itor2=h5.begin();h5_itor2!=h5.end();h5_itor2++) { hash_-map submap=h5_-2->second; hash_映射::迭代器子映射器; 对于(submap_itor=submap.begin();submap_itor!=submap.end();submap_itor++) { cout

C++;好像和我预期的结果不一样 我的C++低,现在学习在STL使用哈什图。当我在以下玩具代码中测试嵌套哈希_映射时,它似乎可以工作: #include <hash_map> #include <iostream> using namespace std; int main() { cout<<"h4 h5"<<endl; hash_map<int,int&> h4; int temp=0; h4.insert(pair<int,int&>(0,temp)); hash_map<int, hash_map<int,int&>> h5; h5.insert(pair<int, hash_map<int,int&>>(1,h4)); hash_map<int, hash_map<int,int&>>::iterator h5_itor=h5.find(1); h5_itor->second.find(0)->second++; h5_itor->second.find(0)->second++; h5_itor->second.find(0)->second++; cout<<h5.find(1)->second.find(0)->second<<endl; int temp2=7; h5.find(1)->second.insert(pair<int,int&>(3,temp2)); h5.find(1)->second.find(3)->second+=100; hash_map<int, hash_map<int,int&>>::iterator h5_itor2; for(h5_itor2=h5.begin();h5_itor2!=h5.end();h5_itor2++) { hash_map<int,int&> submap=h5_itor2->second; hash_map<int,int&>::iterator submap_itor; for(submap_itor=submap.begin();submap_itor!=submap.end();submap_itor++) { cout<<submap_itor->first<<" -> "<<submap_itor->second<<endl; } } return 0; } #包括 #包括 使用名称空间std; int main() { coutsecond++; h5_itor->second.find(0)->second++; coutsecond.find(3)->second+=100; hash_-map::迭代器h5_-2; 对于(h5_itor2=h5.begin();h5_itor2!=h5.end();h5_itor2++) { hash_-map submap=h5_-2->second; hash_映射::迭代器子映射器; 对于(submap_itor=submap.begin();submap_itor!=submap.end();submap_itor++) { cout,c++,hashmap,nested,C++,Hashmap,Nested,以下代码行可能存在一个问题: int count=1; submap.insert(pair<int,int&>(t,count)); 似乎我将count声明为全局变量,但问题仍然存在:-(我在这里使用引用的原因是,如果我不使用它,我发现在嵌套的哈希映射中,计数根本无法更新,尽管它在哈希映射中工作。将计数设置为全局变量意味着所有哈希都将指向相同的计数。注:查找问题的最佳工具是调试器(我应该这样说)Visual Studio将允许您一行一行地查看变量的内容。 int coun

以下代码行可能存在一个问题:

int count=1;
submap.insert(pair<int,int&>(t,count));

似乎我将count声明为全局变量,但问题仍然存在:-(我在这里使用引用的原因是,如果我不使用它,我发现在嵌套的哈希映射中,计数根本无法更新,尽管它在哈希映射中工作。将计数设置为全局变量意味着所有哈希都将指向相同的计数。注:查找问题的最佳工具是调试器(我应该这样说)Visual Studio将允许您一行一行地查看变量的内容。
int count=1;
submap.insert(pair<int,int&>(t,count));
hash_map<int, int&> &submap=tsMap.find(vr)->second;
--------------------^