Reputation: 3
I have a problem where my code just seems to get stuck when trying to insert into a set.
using namespace std;
set<string> * lexset;
void build( const set<string>& word_list )
set<string>::iterator it = word_list.begin();
while( it != word_list.end())
{
cout << *it << "before"<< endl;
lexset->insert(*it);
cout << "after" <<endl;
++it;
cout << "end of while" <<endl;
}
}
It seems to get stuck before the line that prints out 'after'.
The line before insertion prints out a string and I know for sure that wordlist contains a lot of words. This compiles and doesn't loop. If I remove the insert, it iterates through just fine. Why is this insert causing so much trouble?
Upvotes: 0
Views: 92
Reputation: 47854
Allocate memory first for lexset
:
lexset = new set<string>;
And fix your word_list
typo
Upvotes: 2