Earlier I wrote a blog post for OPIG: 

 

Here I’m attaching the codes that I used:

using namespace std;

void save(map const& obj, string const& fname) {
std::ofstream ofs(fname, std::ios::binary);
{
boost::iostreams::filtering_ostreambuf fos;

// push the ofstream and the compressor

fos.push(boost::iostreams::zlib_compressor(boost::iostreams::zlib::best_compression));
fos.push(ofs);

// start the archive on the filtering buffer:
boost::archive::binary_oarchive bo(fos);
bo <> obj;
return obj;
}
}