我有以下情况。以下程序虽然在我运行它时编译得很好,但它停止工作。谁能帮我找到问题?我想我在函数中使用了错误的指针,但我不知道如何修复它并使其工作
#include <fstream>
//some other includes
using namespace std;
struct Book{
string id;
string title;
string authorName;
string authorSurname;
};
int load(Book* booksInfo)
{
int count = 0;
ifstream fin;
fin.open("myfile.txt");
if (!fin.is_open())
{
cout << "Unable to open myfile.txt file\n";
exit(1);
}
while (fin.good())
{
getline(fin, booksInfo[count].id, '#');
getline(fin, booksInfo[count].title, '#');
getline(fin, booksInfo[count].authorName, '#');
getline(fin, booksInfo[count].authorSurname, '#');
count++;
} //end while
fin.close();
return 0;
} //end load()
//some other functions here
int main()
{
Book * bookInfo;
bookInfo = (Book*) malloc(sizeof(Book)*100);
//some code here
load(bookInfo);
//some code here
return 0;
} //end main