双端队列迭代器不可取消引用

Deque iterator not dereferenceable

所以我一直在尝试文件输入和输出来保存 Yugioh 套牌列表,并且我在大多数情况下都能正常工作。我正在使用 deques 存储一个称为 Card 的 class 对象,其中包含所有信息,并使用 Deck class 为每种类型的牌组、主牌、副牌和额外牌保存 Card 对象的双端队列。

所以不管怎样,进入正题。我正在使用本地双端队列来保存有关先前加载的卡片的信息,因为当我加载每张卡片时,我会在双端队列中搜索精确匹配项,然后将数字存储在一个变量中以供输出使用。当我尝试添加到这个名为 "processed" 的本地双端队列时,出现错误。

Debug Assertion Failed! Expression: deque iterator not dereferenceable

void Deck::SaveDeck(std::string filename)
{
    std::ofstream outFile;
    outFile.open(filename.c_str());

    //send the file the deck name
    outFile << this->deckName << "\n";

    //send the deck sizes
    outFile << main_deck_size << " " << side_deck_size << " " << extra_deck_size << "\n";

    //iterator to iterate through the entire deck looking for copies
    std::deque<Card>::iterator iter = main_deckCards.begin();
    std::deque<Card>::iterator iter2 = main_deckCards.begin();

    //deque to hold previously added cards
    std::deque<Card> processed;
    std::deque<Card>::iterator processed_iter = processed.begin();

    string setNAME = "";
    int setNum = 0;
    int quantity = 0;
    bool is_processed = false;

    for (int i = 0; i < main_deck_size; i++)
    {
        //reset processed flag
        is_processed = false;

        //check processed queue for exact card
        for (int j = 0; j < processed.size(); j++)
        {
            if (iter[i].SET_NAME == processed_iter[j].SET_NAME && iter[i].SET_NUM == processed_iter[j].SET_NUM)
            {
                is_processed = true;
                break;
            }
        }

        if(is_processed == false)
        {
            //reset variables
            setNAME = "";
            setNum = 0;
            quantity = 0;

            //draw from the next card
            setNAME = iter[i].SET_NAME;
            setNum = iter[i].SET_NUM;
            quantity++;

            //loop to look for similar cards
            for (int x = i+1; x < main_deck_size; x++)
            {
                if (iter2[x].SET_NAME == setNAME && iter2[x].SET_NUM == setNum)
                {
                    quantity++;
                }
            }

            outFile << setNAME << " " << setNum << " " << quantity << "\n";

            if(setNAME == "LOB-EN")
            {
                //removing this line causes the program to work
                processed.push_back(LOB[setNum]);
            }
        }
    }
}

删除我试图将对象放入双端队列的那一行,程序运行没有错误,只是它多次写入相同的卡片,我想用每张卡片的数量来处理文件,而不是出现在不同行上的倍数。我已经检查了其他问题,问题是由于试图在空双端队列上使用 std::deque::pop_front/back。但是我根本不叫pop_front/back。

关于可能导致错误的原因有什么想法吗?

processed.push_back(LOB[setNum]); 的任何使用都可能会使 processed_iter 无效。

在循环的第一轮,当 processed 开始为空时,或多或少会保证无效。