gpt4 book ai didi

c++ - eof() 函数不工作 C++ 陷入无限循环

转载 作者:行者123 更新时间:2023-11-30 02:59:35 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Why is iostream::eof inside a loop condition considered wrong?

我的 eof() 函数有问题。我的循环没有读取我正在读取的文件的末尾,因此给我留下了一个无限循环。任何帮助或见解将不胜感激。谢谢

 while (!file2.eof()) {

getline (file2, title, ',');
getline (file2, authorf, ',');
getline (file2, authorl, ',');
getline (file2, isbn, ',');
file2 >> pages;
file2.ignore();
file2 >> price;
file2.ignore();
getline(file2, subject, ',');
file2 >> code;
file1.ignore();
file2 >> rentalp;
file2.ignore(10, '\n');


textbook b2(title, authorf, authorl, publisher, pages, isbn, price, code, subject, rentalp);
b2.PrintTbook();
TbookList[j] = b2; //initalizing the first element of the array to b2.
newFile << "Title: " << TbookList[j].getTitle() << "\n" << "Price: " << TbookList[j].getPrice() << "\n\n";
TbookList[j].PrintBook();
j++;
textbookCount++;
}

文本文件如下所示:

数据结构和算法分析实用介绍,Clifford, Shaffer, 0-13-028446-7, 512, 90.00, Computer Science, E, 12.00, 2001数据库系统基础知识,Ramez, AlMasri, 9-780805-317558, 955, 115.50, Computer Science, E, 0.0, 2003

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com