我可以在 STL 地图中使用矢量吗?

发布于 2024-09-04 02:33:51 字数 251 浏览 2 评论 0 原文

我可以声明这样的地图吗?

map<string, vector<string>> mymap;

我认为它是适用的。

然而,事实证明并非如此。

我试过了

map<string, vector<string>*> mymap;

,然后就OK了,

这是什么规则?

Can I declare a map like this

map<string, vector<string>> mymap;

I thought it is applicable.

However, it shows not.

I tried

map<string, vector<string>*> mymap;

and then it is OK

What's the rule of this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丶视觉 2024-09-11 02:33:51

您需要一个额外的空格:

map<string, vector<string> > mymap;
                          ^ see the extra space

如果没有额外的空格,>> 就会被解析为右移运算符。

C++0x 中的规则已被修改,不再需要额外的空间。某些编译器(例如,Visual C++ 2008 及更高版本)已经不需要额外的空间。

You need an extra space:

map<string, vector<string> > mymap;
                          ^ see the extra space

Without the extra space, the >> gets parsed as the right shift operator.

The rules have been modified in C++0x, making the extra space unnecessary. Some compilers (e.g., Visual C++ 2008 and above) already do not require the extra space.

久而酒知 2024-09-11 02:33:51

正如詹姆斯所说,你可以。愚蠢的 C++ 解析 :)

但是,map; > 实际上是
multimap<字符串,字符串>multimap 将一个键映射到多个值。它可能会更方便或更有效,具体取决于您的用例。

You can, as James mentioned. Stupid c++ parsing :)

However, map<string, vector<string> > is effectively a
multimap<string, string>. A multimap maps a key to multiple values. It might be more convenient or more efficient, depending on your use case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文