pointers - C++: Why does dereferencing this vector iterator segfault? -


void insert_string( std::vector<std::string> & strings, const std::string &s ) {      std::vector<std::string>::iterator it=lower_bound(strings.begin(),strings.end(),s);     if(strings.size()>0) std::cout<<*it<<" found\n"; // ****     strings.insert(it,s); } 

when attempting use function, first insertion goes fine. second insertion output "[firststring] found" , segfault. if comment out if/cout line, can repeatedly call , no segfaults occur.

i've tried doing std::string tmp=*it; segfault on line. while printing not huge deal, i'm trying check if string @ position found lower_bound same string trying inserted (i.e., if(*it==s), segfaulting above 2 examples).

what missing here?

thanks!

check condition if it == strings.end(), if don't print it. cause issue. sure string you're trying check in vector of strings?


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -