This is explainined in the section - "rationale" in the documentation. The following changes would make it work; Christian Henning wrote:
Hi there, I was just toying around with the boost serialization lib. Unfortunately I have a problem with serializing a map. Here is what I did:
#include <map> #include <string> #include <iostream> #include <algorithm> #include <fstream>
#include
#include #include using namespace std;
struct Settings { int Brightness; int Contrast; };
// Table indexed by strings typedef pair< string, string > Key; typedef map< Key, Settings* > Table;
int _tmain(int argc, _TCHAR* argv[]) { Table aTable;
aTable[ make_pair("Mueller","Meier") ] = new Settings(); aTable[ make_pair("Meier","Mueller") ] = new Settings(); aTable[ make_pair("Meier","Meier") ] = new Settings();
Settings* pSettings = aTable[ make_pair("Mueller","Meier") ]; pSettings->Brightness = 99; pSettings->Contrast = 8;
{ const Table & stable = aTable;
ofstream ofs( "Settings.txt" ); boost::archive::text_oarchive oa( ofs ); oa << sTable; }
return 0; }
Robert Ramey