如何创建迭代器来解决这个问题?

发布于 2024-11-03 03:49:53 字数 470 浏览 1 评论 0 原文

所以我们有 3 张地图。 args、标头和参数映射。它们是字符串到字符串的映射。
我们还有一个set Settings_Set 其中:

struct settings
{
    string name;  
    set<string> args;
    set<string> headers;
    set<string> params;
};

我们希望将所有映射 -> 第一个字符串与 Settings_Set 的所有项目中的所有集合进行比较。在比较之后或同时,我们想知道

  • 在地图中是否找到了 Settings_Set 中的多个设置
  • 如果在地图中只找到了一项设置(并输出其名称)
  • 如果在地图中没有找到任何设置

那么如何创建这样的事?

So we have 3 maps. args, headers and params maps. They are string to string maps.
We also have a set<settings> Settings_Set where:

struct settings
{
    string name;  
    set<string> args;
    set<string> headers;
    set<string> params;
};

We want to compare all of our maps->first strings with all our sets in all items of Settings_Set. After or while comparing we want to know

  • if more than one of our sttings in Settings_Set were found in our maps
  • if only one setting were found in our maps (and output its name)
  • if none of our settings were found in maps

So how to create such thing?

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

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

发布评论

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

评论(1

野生奥特曼 2024-11-10 03:49:53

你根本不需要提升。另外,即使您称它们为“地图”,我也没有看到任何 std::map 实例。我只看到套装。

这本身并不是一个解决方案,而更多的是解决问题的提示。您可以循环 set 的元素Settings_Set with:

set<settings>::iterator ite = Settings_Set.begin();

while(ite != Settings_Set.end())
{
// do what you need to do in here
// with the corresponding ite->name, ite->args, ite->headers, and ite->params

// Also, you can see if something is in a set by using:
// set<string>::iterator ites = ite->params.find(std::string("some string"));
// which will put the appropriate iterator into ites if one is found
// or ite->params.end() if one is not found

++ite;
}

您应该能够从此以及 std::set 上的标准参考之一将其拼凑在一起:STL 设置引用

(注意我没有故意使用 const_iterator ,因为我假设您可能会更改价值观,正如您在帖子中所说。)

You don't need boost at all. Also, I don't see any instances of std::map even though you call them "maps". I only see sets.

This is not a solution per se, but more a hint to figuring it out. You can loop over the elements of set<settings> Settings_Set with:

set<settings>::iterator ite = Settings_Set.begin();

while(ite != Settings_Set.end())
{
// do what you need to do in here
// with the corresponding ite->name, ite->args, ite->headers, and ite->params

// Also, you can see if something is in a set by using:
// set<string>::iterator ites = ite->params.find(std::string("some string"));
// which will put the appropriate iterator into ites if one is found
// or ite->params.end() if one is not found

++ite;
}

You should be able to piece it together from this and from one of the standard references on std::set: STL set reference

(Note I didn't use const_iterator intentionally, because I'm assuming you might be changing the values, as you said in your post.)

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