我是CLI的新學習者。我的老師將下面的代碼作爲hwo的例子,將對象保存到文件中並從文件中讀取對象。我想我理解代碼。現在,我的老師還發布瞭如何保存對象數組以及讀取對象數組(相同類型)的問題。如何在Visual C++/CLI中寫入和讀取文件?
Q1。我如何知道文件中有多少個對象? Q2302。我應該使用什麼命令來編寫和讀取對象數組?
謝謝。
Player ^Joe = gcnew Player("Joe", "Human", "Thief", 10, 18, 9, 13, 10, 11);
Console::WriteLine("Original Joe");
Joe->Print();
FileStream ^plStream = File::Create((args->Length==1)?args[0]:"Player.dat");
BinaryFormatter ^f = gcnew BinaryFormatter();
f->Serialize(plStream, Joe);
plStream->Close();
plStream = File::OpenRead((args->Length==1)?args[0]:"Player.dat");
Player ^JoeClone = (Player^)f->Deserialize(plStream);
plStream->Close();
Console::WriteLine("\nCloned Joe");
JoeClone->Print();