map与结构体结合使用

来源:互联网 发布:机器人编程入门教程 编辑:程序博客网 时间:2024/05/17 04:19

在编写map中添加结构体的时候,尝试了好多种的方法,网上的这种方法给我提供了一个新奇的思路,在此记录下。


#include <iostream>#include <map> using namespace std; typedef struct alertInfo {    double alertUp;    double alertDown;    alertInfo(double up, double down) {        alertUp = up;        alertDown = down;    };} alert; int main(){    map<int, alert> alert_map;     for (int i = 0; i < 10; i++) {        alert_map.insert(pair<int, alert>(i, alert(240 * i, 200)));    }     for (auto it = alert_map.begin(); it != alert_map.end(); ++it) {        cout << it->first  << " - > " << it->second.alertUp << endl;    }}


0 0
原创粉丝点击