C++ std::map.insert";无法推断…“的模板参数”;

C++ std::map.insert";无法推断…“的模板参数”;,c++,stl,map,C++,Stl,Map,我正试图熟悉STL库,但在理解编译错误时遇到了困难。我使用编译器错误字符串“无法推断…”搜索了其他问题,但没有一个答案适用或相关 错误4错误C2784:“布尔标准::运算符” 您没有包括 char**argv[]必须是const char*argv[] 确保包含字符串标题 #include <map> #include <utility> #include <string> ... std::map<std::string, int> func

我正试图熟悉STL库,但在理解编译错误时遇到了困难。我使用编译器错误字符串“无法推断…”搜索了其他问题,但没有一个答案适用或相关

错误4错误C2784:“布尔标准::运算符”
  • 您没有包括
  • char**argv[]
    必须是
    const char*argv[]

  • 确保包含字符串标题

    #include <map>
    #include <utility>
    #include <string>
    
    ...
    
    std::map<std::string, int> functions;
    functions.insert(std::make_pair(std::string("sin"), 1));
    
    #包括
    #包括
    #包括
    ...
    std::map函数;
    insert(std::make_pair(std::string(“sin”),1));
    
    使用
    std::map::value\u type
    std::pair
    。同时
    函数[“sin”]=1将完美工作:-)@MartinKristiansen我会这么做。它稍微贵一点,并且要求该值是默认可构造的。对于整数来说,这很好,但对于某些类来说,这可能是禁止的或不可能的。关于编辑:插入前不需要定义
    temp
    ,这不是错误,也不需要调用
    make\u pair
    ——尽管它的优点是不需要明确指定类型,
    -构造函数也可以工作。事实上,我会投票支持@MartinKristiansen解决方案,因为它简短易读。谢谢,但我仍然有这两个错误。IntelliSense:没有重载函数的实例,错误C2664无法转换参数…嗯,插入头后,我可以编译没有错误的代码。在包含
    并将
    char**argv[]
    更正为
    const char*argv[]
    之后,也就是。只需添加#include即可解决错误。您还可以执行函数[“newkey”]=1;
    functions.insert(std::make_pair(std::string("sin"), 1));
    
    pair<string, int> temp = pair<string,int>("cos",2);
    functions.insert(temp);
    
    #include <map>
    #include <utility>
    #include <string>
    
    ...
    
    std::map<std::string, int> functions;
    functions.insert(std::make_pair(std::string("sin"), 1));