提出问题 [英] Set question

查看:49
本文介绍了提出问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我意识到我弄错了项目后,希望能够将多个项目放到我的地图中.

我的代码是

Wanted to be able to put multiple items into my set which is in my map after I realised I had got the project wrong.

The code I have is

map<string,set<string> > token;

int main()
{
label = "s1";
token[label].insert("orange", "pears");

return 0;
}



结果我想要在地图中的第一个字符串应该是"s1",并且集合应包含"orange"和"pears"


迅速答复是理想的选择,因为截止日期太短了.



Result I want in the map should be the first string is "s1" and the set should contain "orange" and "pears"


Prompt reply would be ideal as deadline is scary close

推荐答案

您可能想使用 ^ ]

更新:
You probably want to use a multimap[^]

Update:
using namespace std;

typedef map< string , set < string > > tokenmap;

tokenmap token;

int _tmain(int argc, _TCHAR* argv[])
{
    string label("s1");
    set < string > stringSet;
    stringSet.insert("orange");
    stringSet.insert("pears");
    token.insert(tokenmap::value_type(label,stringSet));
    return 0;
}




问候
Espen Harlinn




Regards
Espen Harlinn


Well map 是键,值对的集合.因为您的值是"orange", "pears",这就是您将得到的.

一个.您可以在值插入中插入关键部分
b.当您获取价值时,还请在其上附加您的密钥.
C.扩展地图以为您提供该功能.

简而言之,map 不会为您做这件事.

只是我的2cent.
Well map is a collection of key,value pair. Since your value is "orange", "pears" that is what you will get.

a. You can insert your key part of your value insert
b. when you fetch your value, append to it your key as well.
c. Extend map to have that functionality for you.

In short, the map will not do it for you.

just my 2cent.


这篇关于提出问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆