我遇到一个问题,我的代码在尝试插入集合时似乎卡住了。
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;
}
}
它似乎卡在打印出“after”的那一行之前。
插入之前的行打印出一个字符串,我确信 wordlist 包含很多单词。这编译并且不循环。如果我删除插入,它会很好地迭代。为什么这个插件会造成这么多麻烦?
最佳答案
先为lexset
分配内存:
lexset = new set<string>;
并修复你的 word_list
打字错误
关于c++ - 设置不插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20452129/