stl:map

Hi Folks! I am trying to overwrite the values in an stl:map if certain cretria matches. Can anyone show how to do that??
I have a map<string,time_t>
if the key matches with a given constant then I replace the value of that key with new value.
Suppose the map contains
aol   120102
msft  548710
......
if I iterate through the map and see that aol is there then check its value if its >1000 then I change aol's value to 2000.
If there is no aol then I insert aol with a value of 1000.
TIA.
Please reply ASAP
veselAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

veselAuthor Commented:
Edited text of question.
0
veselAuthor Commented:
Edited text of question.
0
chensuCommented:
Homework?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

jelaiwCommented:
can't you just do:

typedef map<string,time_t>::iterator LI

for (LI i=somemap.begin(); i!=somemap.end(); i++)
{
    if (somemap[key]==sometime)
        somemap[key]=newtime;
}

isn't this in your reference book?

jw
0
arikkaCommented:
void foo(map<string,int>& m, int oldVal, int newVal, char*s key)
{
  map<string,int>::iterator p = find(key);
  if (p!=m.end()) {             // key was found
    if (p->second > oldVal)
        p->second = newVal;
  }
  else {                       // not found  
    m.insert(make_pair(key, newVal));
  }
}
0
veselAuthor Commented:
I asked a question not to bitch at me!!!
Thx for the folks who answered it....
Arrika Please post your comment with answer I will give you the points.

Thx
0
arikkaCommented:
void foo(map<string,int>& m, int oldVal, int newVal, char*s key)
{
  map<string,int>::iterator p = find(key);
  if (p!=m.end()) {             // key was found
    if (p->second > oldVal)
        p->second = newVal;
  }
  else {                       // not found    
    m.insert(make_pair(key, newVal));
  }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
veselAuthor Commented:
Thx for that,Arrika!this is a part of a big module I was just missing tiny details. No its not a HW I am way to old for all that.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.