[英]Is there a limit on the size of std::set::iterator?
我有一个std :: set字符串,我想遍历它们,但是对于set的不同大小,迭代器的行为有所不同。 下面给出的是我正在处理的代码片段:
int test(set<string> &KeywordsDictionary){
int keyword_len = 0;
string word;
set<string>::iterator iter;
cout << "total words in the database : " << KeywordsDictionary.size() << endl;
for(iter=KeywordsDictionary.begin();iter != KeywordsDictionary.end();iter++) {
cout << *iter;
word = *iter;
keyword_len = word.size();
if(keyword_len>0)
Dosomething();
else
cout << "Length of keyword is <= 0" << endl;
}
cout << "exiting test program" << endl;
}
该代码工作正常& *iter
被取消引用和分配word
,直到大小KeywordsDictionary
大约是15000然而,当大小KeywordsDictionary
超过15000的增加,
cout << *iter;
正在正确打印KeywordsDictionary
所有内容。 *iter
的指针未取消引用且未分配给word
。 word
只是一个空字符串。 编辑:并且该程序的输出是:
total words in the database : 22771
�z���AAAADAAIIABABBABLEABNABOUTACACCEPTEDACCESSACCOUNT...
Length of keyword is <= 0
exiting test program
所以基本上,我猜循环只会执行一次。
尝试将keyword_len声明为
std::string::size_type keyword_len = 0;
代替
int keyword_len = 0;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.