尝试插入到地图时的C ++编译问题 [英] C++ compilation issue when trying to insert into a map
本文介绍了尝试插入到地图时的C ++编译问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到的C ++编译器错误是:
C++ compiler error that i am getting is :
line 27: Error: Could not find a match for
std::multimap<std::string, std::vector<std::string>,
std::less<std::string>,
std::allocator<std::pair<const std::string,
std::vector<std::string>>>>
::insert(std::pair<std::string, std::vector<std::string>>)
needed in main().
1 Error(s) detected.
以下是我的程序:
#include<iostream>
#include<sstream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
typedef multimap<string, vector<string> > mos_map;
typedef multimap<string, vector<string> >::iterator mos_map_it;
int main()
{
mos_map mos;
mos_map_it it;
vector<string> v1;
v1.push_back("a");
v1.push_back("b");
v1.push_back("c");
v1.push_back("mo1");
std::string a(*(v1.end()-1));
mos.insert(std::pair< std::string, vector< std::string > >(a,v1));
//Is the above not the right way to to insert an element into the map?
return 0;
}
上面的代码在我试图插入一个向量时会抛出一个编译错误
The above code is throwing a compilation error when i try to insert a vector as value with a string as a key.I am working on solaris.
推荐答案
在地图中插入元素的正确方法是:
Right way to insert element in map is:
mos[a] = v1
(由于map已重载operator [])
(due to map has overloaded operator[])
这篇关于尝试插入到地图时的C ++编译问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文