boost serialization

Hi,

I have something like this:

...//header files
class A{
private:
std::vector<uint16_t>r;
std::vector<uint8_t>s;
std::vector<float>t;
public:
...//methods.. no constructor or destructor
friend class B;
}

class B{
private:
std::string s;
int a,b;
std::map<int, std::vector<A>> X,Y,Z;
public:
....//methods including constructors and destructors
}

int main(){
..
std::map<std::string,std::vector<B>>myMap;
...
}

Now I want to write myMap to a file and then read from it. How could I go about it...?

I'm new to boost and would like some advise, in this regard.

Thanks in advance.
Have you read the tutorial? http://www.boost.org/doc/libs/1_58_0/libs/serialization/doc/index.html . Your question is almost identical to one on SO here: http://stackoverflow.com/questions/16075953/c-serialize-deserialize-stdmapint-int-from-to-file - you just need to add in a serialize function for your classes B and A.

You'll also want to add in the headers for string and vector from Boost instead:
1
2
3
4
5
6
7
8
9
#include <boost/serialization/map.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp>

// #include <map>
// #include <string>
// #include <vector>

// ... 
Topic archived. No new replies allowed.