I am looking to increment the double of a pair when iterating through a map.
The map is created as such:
typedef pair<string,string> Name;
map<Name,double> paidEmploy;
After I get everything from cin and add it to the map, it will not add an object if the name is already in the map (obviously). If the insert then fails, I loop through the map to find the position of the already inserted name. I then want to access the double of the map to increment by the next amount. How do I access this?
Here is what I'm doing so far:
map<Name,double> paidEmploy;
string line, fn, ln, date;
double paid;
while(getline(cin, line)){
istringstream(line) >> date >> fn >> ln >> paid; // assume all lines are correct
if(paidEmploy.insert(pair<pair<string,string>,double>(pair<string,string>(fn,ln),paid)).second == false){
for(auto it = paidEmploy.begin(); it != paidEmploy.end(); it++){
if(it->second.first == fn && it->second.second == ln){
it->third += paid;
break;
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire