Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-05-24 15:20:27


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 <boost/archive/text_iarchive.hpp>
> #include <boost/archive/text_oarchive.hpp>
> #include <boost/serialization/map.hpp>
>
> 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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net