Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   help with using associative containes ( map ) (http://www.go4expert.com/forums/help-using-associative-containes-map-t2438/)

blork98 5Jan2007 07:27

help with using associative containes ( map )
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 Code:

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;         

blork98 5Jan2007 08:33

Re: help with using associative containes ( map )
never mind, he he dumb mistake

All times are GMT +5.5. The time now is 12:13.