簡體   English   中英

std :: set :: iterator的大小是否有限制?

[英]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的增加,

  1. 打印語句cout << *iter; 正在正確打印KeywordsDictionary所有內容。
  2. 但指向迭代器*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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM