マークがhttp://www.boost.org/doc/libs/1_49_0/libs/serialization/doc/index.htmlを使用して指摘したように、データをオブジェクトにパッケージ化またはカプセル化し、それらをシリアル化する必要があります。そこに例と詳細なヘルプがあります。非常に単純なケースを検索します。:)
編集:私はあなたのために簡単で汚い例を作りました。楽しみ。(整形でごめんなさい。)
#include <cstddef> // NULL
#include <iomanip>
#include <iostream>
#include <fstream>
#include <iterator>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/assume_abstract.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp>
class family_names
{
friend class boost::serialization::access;
std::vector<std::string> m_names;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & m_names;
}
friend std::ostream & operator<<(std::ostream &os, const family_names& fn);
public:
family_names(const std::vector<std::string>& names)
: m_names(names)
{}
family_names() {}
};
std::ostream & operator<<(std::ostream &os, const family_names& fn)
{
std::ostream_iterator<std::string> out_it (std::cout,", ");
std::copy(fn.m_names.begin(), fn.m_names.end(), out_it);
return os;
}
void save(const family_names &s, const char * filename){
// make an archive
std::ofstream ofs(filename);
boost::archive::text_oarchive oa(ofs);
oa << s;
}
void restore(family_names &s, const char * filename)
{
// open the archive
std::ifstream ifs(filename);
boost::archive::text_iarchive ia(ifs);
// restore the family names from the archive
ia >> s;
}
int _tmain(int argc, _TCHAR* argv[])
{
std::vector<std::string> vec_names;
vec_names.push_back("Jason");
vec_names.push_back("Mark");
vec_names.push_back("Ludmilla");
family_names names(vec_names);
std::string filename = "c:\\Dev\\demofile.txt";
std::cout << names << std::endl;
save(names, filename.c_str());
family_names names_back;
restore(names_back, filename.c_str());
std::cout << names_back << std::endl;
return 0;
}