下面是C++的檔案保存操作,目的是保存多個Teacher物件(元資料用鏈表存盤的)到檔案中,我測驗了保存和讀取的功能都是可以成功的,但是在保存完和讀取完之后(也就是執行完write和read之后)程式都會進入阻塞模式卡死,無法繼續執行,這是為什么,有沒有大佬有解決辦法
//寫入檔案
bool writeFile(TL* tl) {
if (isNull(tl->next) || tl->next->teacher.getNumber() == 0) {
cout << "NULL" << endl;
return false;
}
TL* node = tl;
fstream outfile("d:\\try.txt", ios::out | ios::binary);
if (!outfile) {
cerr << "open file error!";
}
while (node->next)
{
Teacher teacher = node->next->teacher;
outfile.write((char*)&teacher, sizeof(teacher)); //寫入資料
node = node->next;
}
outfile.close();
return true;
}
uj5u.com熱心網友回復:
檢查一下鏈表末尾的next是不是為0轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/58516.html
標籤:C++ 語言
上一篇:利用代碼程式求時間復雜度
