我有以下地圖:顯示一個字符串,矢量<int>地圖在C++
std::map<std::string, std::vector<int> > my_map;
我這樣插入鍵和值在我的地圖:
my_map.insert(std::pair<std::string, std::vector<int> >(nom,vect));
如何打印兩鍵和我的地圖的值?
我已經測試:
for(std::map<std::string, std::vector<int> >::iterator ii=my_map.begin(); ii!=my_map.end(); ++ii)
{
std::cout << (*ii).first << ": " << (*ii).second << std::endl;
}
但出於某種原因,我得到這個錯誤:
error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘std::vector<int>’)
std::cout << (*ii).first << ": " << (*ii).second << std::endl;
你怎麼能打印'std :: vector'?你不能這樣做,除非你通過爲'operator <<'提供一個過載來定義它是如何被打印的。'' –
user463035818
你需要遍歷'std :: vector',或者在原地進行,或者通過重載'運營商<<'爲這種類型(我不建議。) –
Tobias
該死的我是一個初學者,我真的不需要每個評論員在這個論壇downvote一篇文章,當他們找到答案很明顯 –