[英]Set is not inserting
我有一個問題,我的代碼似乎在嘗試插入集合時卡住了。
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;
}
}
它似乎在打印出“之后”的行之前卡住了。
插入前的行打印出一個字符串,我確信wordlist包含很多單詞。 這編譯並且不循環。 如果我刪除插入,它會反復進行。 為什么這個插件會造成這么多麻煩?
首先為lexset
分配內存:
lexset = new set<string>;
並修復你的word_list
拼寫錯誤
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.