用另一个类的类对象的C ++序列化

尝试使用boost序列化,但迄今为止尚未成功写入文件。这是我的代码,以及如何在代码中序列化和反序列化对象 SRegister record 是另一个继承的类(不知道该类的记录成员变量并使用文本初始化)文件(其SDK)。请帮我解决一下这个。这是.h和.cpp文件的代码

/**file: student.h**/ 

class students
{  

public:
 students(const char* path): record(path) {}

 ~students(){}

 int Register(string name,int year)
 {
   return record.Register(name,year);
 }

 int map_studentid_name(int index,std::string name)
 {
   student_map.insert(std::pair<int,string>(index,name));
 }


private:
 StudentRecord record;
 std::map<int,string> student_map;

};


/**File: student.cpp**/

#include "student.h"
#include <fstream>

using namespace std;

int main(int argc,char **argv)
{

 const char *path_file = "data.txt";
 if ((path_file != NULL) && (path_file[0] == '\0'))
 {
   return (0);
 }

 students *SRegister = new students("school.txt");

 std::ifstream file(path_file);
 std::string str;
 int count = 1;
 while (std::getline(file,str))
 {
   // get the line from text file - name year
   std::string delimiter = " ";
   string name;
   int year;
   size_t pos = 0;
   std::string token;
   while ((pos = str.find(delimiter)) != std::string::npos)
   {
     name = str.substr(0,pos);
     str.erase(0,pos + delimiter.length());
   }
   year = str;


   // Register student in data base
   findex = SRegister->Register(name,year);

   FRegister->map_studentid_name(findex,name);
   count++;
 }

/* Now i neeed to save/ serialize  the SRegister into a file */


}
fangke45 回答:用另一个类的类对象的C ++序列化

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3010574.html

大家都在问