#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    24
    Rep Power
    0

    stl map find function


    Hi,

    I am trying to figure out how to see if a find in a map didn't find what I was looking for....if i do:

    map<....>::iterator it = NULL;
    it = mapInstance.find("hello");

    and suppose "hello" doesn't exist in the map, then how will I know?? 'it' will not point to NULL if the find is unsucessful, am I correct? How can I figure out the sucess of the find?

    THanks,

    Kavi
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    USA
    Posts
    286
    Rep Power
    13
    The find function returns an interator to the specified key. If the key isn't found, then it returns an iterator to the end of the map.

    So...

    Code:
    if (it != mapInstance.end ())
    {
        // Key found
    }
    else
    {
        // Key NOT found
    }
    Jon Sagara

    "Me fail English? That's unpossible!"
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    24
    Rep Power
    0

    Thanks


    Thanks for ur help, Jon!
    :)
    Kavi

IMN logo majestic logo threadwatch logo seochat tools logo