链表正在替换

Linked List is Replacing

本文关键字:替换 链表      更新时间:2023-10-16

我正在使用C++链表和Visual Studio来创建表单并将其保存到csv文件中。它在这里发生的问题是它工作正常,每次我添加时,它都会完美添加。但是在我关闭程序并重新打开并再次添加后,整个数据是 csv 文件清除并添加一个新文件。

所以基本上当我重新运行程序时,它不会添加产品,而是全部删除然后添加。

void BootLinkedList::bootSave()
    {
        ofstream infile;
        infile.open("footwear2.csv");
        Boots *node = head;
        while (node != NULL)
        {
            infile << node->getCode() << "," << node->getBrand() << "," << node->getColor() << "," << node->getSize() << "," << node->getPrice() << "," << node->getType() << "," << node->getSoleStyle() << "," << node->getBootType() << "," << node->getBootStyle() << "," << "-" << endl;
            node = node->getNext();
        }
        infile.close();
    }

更改

 infile.open("footwear2.csv");

 infile.open("footwear2.csv", ios::out | ios::app);

见参考文献中的拘留