索引标准/提升::按结构元素映射
index std/boost::map by struct element
我发现这个很好的问题与我想做的事情略有相反。
我仍然太菜鸟,无法真正理解发生了什么。 (我现在几乎不熟悉基本语法)
我想做的是用struct
的一个元素索引struct
的std::map
。
所以,如果我有
struct accountStruct{
string accountName;
double total;
};
我想用accounts[accountName].total
称accountStruct
std/boost::map
的total
.
请告诉我怎么做。
您可以使用std::map<std::string, accountStruct>
.但是,当您将元素插入地图时,这不会自动填充accountStruct
中的accountName
。std::map<K, V>
当然不会考虑使用用户提供的字段struct
作为键。不过,您可能希望直接使用std::map<std::string, double>
。...或将帐户名称排除在accountStruct
struct accountStruct {
double total = 0.0;
// possibly other members
};
std::map<std::string, accountStruct> m;
相关文章:
- 使用不带参数的函数访问结构元素
- 访问类lintalizer列表中的结构元素
- 如何为 c++ 的不同变量类型的结构元素创建动态数组?
- 结构元素名称要 cout?
- C++结构元素(成员变量)的数量
- 如何在类中声明静态 const 结构元素
- 在地图中搜索结构元素
- 在C++中传递结构数组 - 被调用函数中不存在结构元素,如何正确传递向量?
- 结构元素C 的枚举
- 将结构元素地址设置为C 中的null(单链接列表)
- OPENCV:为击中创建一个正方形结构元素
- 如何将结构元素传递给异步线程
- C - 基于另一个元素对结构元素进行排序
- 无法从传递到 pthread 的结构中访问结构元素
- 矢量的打印结构元素
- C结构元素对齐(ansi)
- 用3x3结构元素进行两次形态扩张,等于用6x6结构元素进行一次形态扩张
- 创建结构元素的动态数组,然后创建该结构的动态数组.C++
- 访问地图数据结构中的结构元素
- 尝试在文本文件中添加结构元素而不覆盖它