我按照这个答案编写了下面的代码。但它给出了以下编译错误。我认为这是因为make_pair不能接受另一个make_pair作为参数。那么替代方法是什么呢?
error: no matching function for call to ‘std::map<std::basic_string<char>, std::map<float, int>
>::insert(std::pair<std::basic_string<char>, std::pair<double, int> >)’
以下是代码
#include <iostream>
#include <map>
#include <string>
int main() {
std::map<std::string, std::map<float, int> > map1;
std::string string1 = "alpha";
map1.insert(std::make_pair(string1, std::make_pair(1.1, 1)));
return 0;
}
1.1
,然后搜索一个计算出来的key = 1.0 + 0.1
可能会让你感到惊讶。 - WhozCraig