help with using associative containes ( map )

Discussion in 'C' started by blork98, Jan 5, 2007.

  1. blork98

    blork98 New Member

    Joined:
    Jan 5, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hi, guys.... trying to write a function that checks to see if a number already exists in a vector...

    anyway, the function returns true if the number does not exist and false it it does not.
    the parameter const string& word is the key to the map

    my problem is that the program crashes. if i take out this function, then it works fine, as long as i dont use it in the main program. i think the problem is in the for loop, because the program again works fine if i comment out the for loop.

    thanks in advance for any help.. hope i described the prob ok

    HTML:
    bool is_not_present( const map<string, vector<int> >& r, const int& line, const string& word)
    {
         map<string, vector<int> >::const_iterator i = r.find(word);
         bool flag = true;
         for( vector<int>::const_iterator it = i->second.begin(); it != i->second.end(); ++it ){ 
              if(  *it == line) flag = false;    
         }
         return flag;          
    }
     
  2. blork98

    blork98 New Member

    Joined:
    Jan 5, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    never mind, he he dumb mistake
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice