std::time_t date; std::string name; int bitrate; bool stereo; public: void serialize(); void deserialize(); //.. }; void MP3_clip::serialize() { { int size=name.size();// store name's length //empty file if it already exists before writing new data ofstream arc("mp3.dat", ios::binary|ios::trunc); arc.write(reinterpret_cast<char *>(&date),sizeof(date)); arc.write(reinterpret_cast<char *>(&size),sizeof(size)); arc.write(name.c_str(), size+1); // write final '\0' too arc.write(reinterpret_cast<char *>(&bitrate), sizeof(bitrate)); arc.write(reinterpret_cast<char *>(&stereo), sizeof(stereo)); } |
正在阅读:C++学习:在C++中创建持久对象C++学习:在C++中创建持久对象
2004-02-14 09:34
出处:PConline
责任编辑:linjixiong
键盘也能翻页,试试“← →”键