在编写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;
}
}