正在阅读:C++学习:在C++中创建持久对象C++学习:在C++中创建持久对象

2004-02-14 09:34 出处:PConline 作者:Danny Kalev/CSDN 责任编辑:linjixiong

    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));

   }

键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品