C++ 将元素插入多重映射的语法<;字符串,向量<;配对<;字符串,int>&燃气轮机&燃气轮机;

C++ 将元素插入多重映射的语法<;字符串,向量<;配对<;字符串,int>&燃气轮机&燃气轮机;,c++,vector,syntax,multimap,std-pair,C++,Vector,Syntax,Multimap,Std Pair,我的问题是如何在表单的多重映射中插入一些元素 multimap<string, vector<pair<string, int>>> someMap; //std skipped to simplify multimap-someMap//跳过std以简化 我尝试了不同的语法,我认为最接近的可能是这个 someMap.insert(pair<string,vector<pair<string, int>>>(someSt

我的问题是如何在表单的多重映射中插入一些元素

multimap<string, vector<pair<string, int>>> someMap; //std skipped to simplify
multimap-someMap//跳过std以简化
我尝试了不同的语法,我认为最接近的可能是这个

someMap.insert(pair<string,vector<pair<string, int>>>(someString1, vector<pair<string, int>> { pair<string, int> (someString2, someInt) }));
someMap.insert(pair(someString1,vector{pair(someString2,somesint)});

不幸的是,它不起作用。任何提示???

第一对的类型是错误的

pair<string,vector<string, int>>
                   ^^^^^^^^^^^
对
^^^^^^^^^^^
无论如何,我建议:

multimap<string, vector<pair<string, int>>> someMap;
vector<pair<string,int>> obj;
someMap.insert(make_pair("hello", obj));
multimap-someMap;
向量obj;
插入(make_pair(“hello”,obj));
或者如果您坚持使用该语法(详细模式):

multimap-someMap;
string someString2=“hello”;
string someString1=“世界”;
int-someInt=42;
insert(pair(someString1,vector{pair(someString2,somesint)});

这需要C++11。第一对的类型错误

pair<string,vector<string, int>>
                   ^^^^^^^^^^^
对
^^^^^^^^^^^
无论如何,我建议:

multimap<string, vector<pair<string, int>>> someMap;
vector<pair<string,int>> obj;
someMap.insert(make_pair("hello", obj));
multimap-someMap;
向量obj;
插入(make_pair(“hello”,obj));
或者如果您坚持使用该语法(详细模式):

multimap-someMap;
string someString2=“hello”;
string someString1=“世界”;
int-someInt=42;
insert(pair(someString1,vector{pair(someString2,somesint)});

这需要C++11。第一对的类型错误

pair<string,vector<string, int>>
                   ^^^^^^^^^^^
对
^^^^^^^^^^^
无论如何,我建议:

multimap<string, vector<pair<string, int>>> someMap;
vector<pair<string,int>> obj;
someMap.insert(make_pair("hello", obj));
multimap-someMap;
向量obj;
插入(make_pair(“hello”,obj));
或者如果您坚持使用该语法(详细模式):

multimap-someMap;
string someString2=“hello”;
string someString1=“世界”;
int-someInt=42;
insert(pair(someString1,vector{pair(someString2,somesint)});

这需要C++11。第一对的类型错误

pair<string,vector<string, int>>
                   ^^^^^^^^^^^
对
^^^^^^^^^^^
无论如何,我建议:

multimap<string, vector<pair<string, int>>> someMap;
vector<pair<string,int>> obj;
someMap.insert(make_pair("hello", obj));
multimap-someMap;
向量obj;
插入(make_pair(“hello”,obj));
或者如果您坚持使用该语法(详细模式):

multimap-someMap;
string someString2=“hello”;
string someString1=“世界”;
int-someInt=42;
insert(pair(someString1,vector{pair(someString2,somesint)});
这需要C++11。请尝试以下操作

#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <utility>

int main() 
{
    typedef std::pair<std::string, int> value_type;
    std::multimap<std::string, std::vector<value_type>> m; 

    m.insert( { "A", std::vector<value_type>( 1, { "A", 'A' } ) } );

    return 0;
}
试试下面的方法

#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <utility>

int main() 
{
    typedef std::pair<std::string, int> value_type;
    std::multimap<std::string, std::vector<value_type>> m; 

    m.insert( { "A", std::vector<value_type>( 1, { "A", 'A' } ) } );

    return 0;
}
试试下面的方法

#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <utility>

int main() 
{
    typedef std::pair<std::string, int> value_type;
    std::multimap<std::string, std::vector<value_type>> m; 

    m.insert( { "A", std::vector<value_type>( 1, { "A", 'A' } ) } );

    return 0;
}
试试下面的方法

#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <utility>

int main() 
{
    typedef std::pair<std::string, int> value_type;
    std::multimap<std::string, std::vector<value_type>> m; 

    m.insert( { "A", std::vector<value_type>( 1, { "A", 'A' } ) } );

    return 0;
}


用于避免键入和拼写多余的类型信息。@Csq我添加了跳过所有std::的注释,以稍微简化代码。不管怎样,谢谢你的提示不起作用。。。怎样?错误?警告崩溃不要让我们悬而未决。@JonathanPotter语法不正确。这是我最后一次尝试someMap.insert({someString1,vector@JonathanPotter错误:常量表达式族中的临时非文字类型“std::pair”。插入({name,vectorUse以避免键入和拼写多余的类型信息。@Csq我添加了注释,跳过了所有std::以简化代码。无论如何,感谢提示无法工作…如何?错误?警告?崩溃?不要让我们悬而未决。@JonathanPotter语法不正确。这是我尝试someMap的最后一个版本。insert({1,vector@JonathanPotter错误:常量表达式族中的临时非文字类型“std::pair”。插入({name,vectorUse以避免键入和拼写多余的类型信息。@Csq我添加了注释,跳过了所有std::以简化代码。无论如何,感谢提示无法工作…如何?错误?警告?崩溃?不要让我们悬而未决。@JonathanPotter语法不正确。这是我尝试someMap的最后一个版本。insert({1,vector@JonathanPotter错误:常量表达式族中的临时非文字类型“std::pair”。插入({name,vectorUse以避免键入和拼写多余的类型信息。@Csq我添加了注释,跳过了所有std::以简化代码。无论如何,感谢提示无法工作…如何?错误?警告?崩溃?不要让我们悬而未决。@JonathanPotter语法不正确。这是我尝试someMap的最后一个版本。insert({1,vector@JonathanPotter错误:常量表达式族中的临时非文字类型“std::pair”。插入({name,vectorOh很抱歉输入错误,显然它应该是对的谢谢,它现在正在工作。我必须检查我在哪里输入了错误,因为我在开始时尝试了非常类似的代码。谢谢你的时间。@user3119781很高兴我帮了你!如果它解决了你的问题,请将此标记为可接受的答案。嗯,有趣的是,在我修复了该类型之后o如果您查看第一篇文章,我的代码看起来与您的代码相同,但我直到将两者进行比较后才意识到:)哦,对不起,输入错误,显然应该是对的谢谢,它现在正在工作。我必须检查我在哪里输入了错误,因为我在开始时尝试了非常类似的代码。谢谢你的时间。@user3119781很高兴我帮了你!如果它解决了你的问题,请将此标记为可接受的答案。嗯,有趣的是,在我修复了这个输入错误后,我的代码看起来很有趣如果你查看第一篇帖子,你会发现它和你的一样,但直到我将两者进行比较后,我才意识到:)哦,对不起,输入错误,显然应该是对的谢谢,它现在正在工作。我必须检查我在哪里输入了错误,因为我在开始时尝试了非常类似的代码。谢谢你的时间。@user3119781很高兴我帮了你!如果它解决了你的问题,请将此标记为可接受的答案。嗯,有趣的是,在我修复了这个输入错误后,我的代码看起来很有趣如果你查看第一篇帖子,你会发现它和你的一样,但直到我将两者进行比较后,我才意识到:)哦,很抱歉输入错误,显然应该是对的谢谢,它现在正在工作。我必须检查我在哪里输入了错误,因为我在开始时尝试了非常类似的代码。谢谢您的时间。@user3119781很高兴我帮了忙!如果它解决了您的问题,请将此标记为已接受的答案