我的代碼:C++程序讀取文件
void load_books(){
ifstream myfile(path, ios::in);
if (myfile.fail()){
cout << "coudln't open file" << "\n\n";
}
else{
while (myfile){
myfile >> book1[i].id >> book1[i].title >> book1[i].p_name >> book1[i].p_address >> book1[i].aut_name;
myfile >> book1[i].aut_nationality >> book1[i].date >> book1[i].status;
cout << book1[i].id << "\ " << book1[i].title << "\ " << book1[i].p_name << "\ " << book1[i].p_address << "\ " << book1[i].aut_name;
cout << "\ " << book1[i].aut_nationality << "\ " << book1[i].date << "\ " << book1[i].status << endl;
i++;
}
myfile.close();
}
}
應該輸出什麼文件包含但我得到這個命令
個111·艾哈邁德·優素福大聲笑否是哈立德·15
222 adas asd sdt huy mjmj mjg2 20
的前兩行是正確的,但我不知道爲什麼它輸出的最後2個零(0)
您閱讀前檢查。 – LogicStuff
@LogicStuff我不明白!我是新的文件 –
請考慮超載'>>'您的書類。 – erip