Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2006-08-04 22:49:54


use a stringstream instead of a file stream.

#include <sstream> // or maybe #include <stringstream> - I forget.

Robert Ramey

  "Anil Krishna" <akrishna876_at_[hidden]> wrote in message news:d27926bf0608041513i6049b7cas247dd30d70d40601_at_mail.gmail.com...
  Hi All,
  Currently I am using the boost serialization library to serialize and the following structure:

  typedef list<int> testList;
  typedef testList::iterator lIter;
  typedef map<int, testList> testMap;
  typedef testMap::iterator tIter;
  testMap _tMap;
     template<class Archive>
     void serialize(Archive &ar, const unsigned int version)
     {
       ar & _tMap;
     }

  int main()
  {

    test_map tm;
    ofstream ofs("map_details.txt");

    tm.fillMap();
    //tm.display();

    boost::archive::binary_oarchive oa(ofs);
    oa << (const test_map)tm;
    ofs.close();

    test_map newTm;
    ifstream ifs("map_details.txt", std::ios::binary);
    boost::archive::binary_iarchive ia(ifs);
    ia >> newTm;
    ifs.close();

    newTm.display();
  }

  In the above code, I am saving the map to a binary file and retrieving it from the file. Instead of that I would want to serialize the data into a char buffer and restore it from the buffer.

  This is useful for message communication, where I would like to send the map as a message from one process to another using socket communications.

  Can you any one let me know, how this can be done in boost?

  Regards,
  Anil

------------------------------------------------------------------------------

  _______________________________________________
  Boost-users mailing list
  Boost-users_at_[hidden]
  http://lists.boost.org/mailman/listinfo.cgi/boost-users



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