使用类型<int,vector <int >>插入到map中

Som*_*ken 2 c++ insert vector map

我有这个代码:

map< int , vector< int>> testmap;
vector<int> testvector;
testvector.push_back(10);
testmap.insert(1, testvector);
Run Code Online (Sandbox Code Playgroud)

这段代码给了我一个错误,告诉我没有重载函数来匹配参数列表.

谁能告诉我为什么会这样?我正在尝试将矢量插入到地图中,但此方法似乎不起作用.

jua*_*nza 5

std::map::insert匹配您传递的参数没有重载.这可行:

auto p = testmap.insert(std::make_pair(1, testvector));

std::cout << std::boolalpha;
std::cout << "Did insert succeed? " << p.second << std::endl;
Run Code Online (Sandbox Code Playgroud)

如果地图中没有带有键的元素,这将成功1.