C++使用结构作为<map,<map,vector的数据>>
c++ using structs as data for a <map, <map, vector>>
我在尝试加载具有另一个地图/矢量组合作为带有结构的值的地图时遇到问题。 下面是我的代码,我试图尽可能简化:
//These are the structs
struct Order
{
std::string A;
std::string B;
};
struct Card
{
std::string C;
std::string D;
};
struct Item
{
std::string E;
std::string F;
};
//this is the method that will read and load the map
void LoadMap(ListofValues object)
{
std::map<Order, std::map<Item, std::vector<Card>>> records; //THIS is the data structure I'm trying to store into
//ListofValues is a list passed that holds all these values that will need to be put into my map
for(std::vector<ListofValues>::iterator vIter= object.begin(); vIter != object.end(); ++vIter)
{
std::string sReceiptRecord = (*vIter).getReceipt(m_StdOrderConfirmVer);
Order order = {(*vIter).getA,(*vIter).getB};
Item item = {(*vIter).getC,(*vIter).getD};
Card card = {wws::String((*vIter).getE), (*vIter).getF};
records[order][item].push_back(card); //load into my map
}
}
因此,我将传递一个包含所有值列表的对象(ListofValues)。 我将遍历该列表,并使用 getter 方法将这些值存储到结构中(getE 返回一个 Long,这就是需要转换的原因)。我错过了什么步骤
我得到的一个错误是:
error C2678: binary '<' : no operator found which takes a left-hand operand of type 'const Order' (or there is no acceptable conversion)
您需要提供一个运算符<,以便将结构用作映射的键,请参阅以下问题:结构作为 std::map 中的键
ListOfValues
是传递给LoadMap
的参数的TYPE,object
是实际变量。
在你的 for 循环中,你需要说object.begin()
和object.end()
。
我得到的编译器错误与你说的非常不同。 你发布了正确的代码吗?
这是我看到的:https://godbolt.org/g/xl4zWw
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- std::map<struct,struct>::find 找不到匹配项,但是如果我循环通过 begin() 到 end(),我在那里看到匹配项
- 使用一个考虑到std::map中键值的滚动或换行的键
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 允许从 std::map 的密钥窃取资源?
- EASTL矢量<向量<int>>连续的
- 有没有办法对std::unordered_set、std::unrdered_map、std::set、std::map
- 将重物插入std::map
- 使用通用值初始化 std::map,不重复
- 仅包含可移动 std::map 的类的移动构造函数不起作用
- C++:当所有条目都保证是唯一时,替代 std::map
- 使用模板化的键类型定义 std::map,该键类型基于作为参数接收的函数
- 如果 KEY 是 std::list 或 std::vector 而不是值,那么 std::map 的默认行为是什么?
- 使用字符数组作为 Map 中的键
- C++如何创建 std::map
- C++ equivalent to Java Map getOrDefault?
- 从其他容器中移动构造"std::map"
- 如何使用 uint64_t 键类型从 std::map<int, std::string> 返回值?
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- std::map<std::set, double> AND std:<long>map< std::p air<long, long>, double>