因此,我一直在尝试输入和输出文件来保存Yugioh卡片组列表,并且大部分时间我都可以使用它。我正在使用双端队列来存储称为Card的类对象,该类对象包含所有信息,而Deck类用于为甲板,主甲板,侧面和其他每种类型的Card对象保留双端队列。

所以无论如何,解决问题。我正在使用本地双端队列来保存先前加载的卡上的信息,因为当我加载每张卡时,我会在双端队列中搜索精确匹配项,然后将数字存储在变量中以供输出。当我尝试添加到称为“已处理”的本地双端队列时,出现错误。


  调试断言失败!表达式:双端队列迭代器不可取消引用


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开始为空时,或多或少会确保无效。

关于c++ - 双端队列迭代器不可取消,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41783232/

10-12 21:11