-
December 30th, 2016, 07:41 AM
#1
How to iterate over archive in boost::serialization
I have saved multiple map values inside a file using boost serialization, now my problem is i don't know exactly how i can read all of those maps: Till now i've done these much;
Code:
#include <map>
#include <fstream>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/map.hpp>
int main(int argc,char** argv) {
std::ofstream s("tmp.oarchive");
std::map<int,int> m, m1, m2;
m[1] = 100;
m[2] = 200;
m1[123]=3222; m2[1]=23;
m1[1111]=232; m2[23]=1;
{
boost::archive::text_oarchive oa(s);
oa << m; oa << m1; oa << m2;
}
std::map<int,int> n; std::map<int,int> n1;
{
std::ifstream s("tmp.oarchive");
boost::archive::text_iarchive ia(s);
if(s.is_open()) {
ia >> n;
std::cout<<n[1]<<"\t"<<n[1111]<<std::endl;
}
}
}
Here the number of map object can be very large, so is their any kind of iterator of function similar to fseek() to read the input archive like in normal text file. I found similar question here but i think that is just for class type not for stl. so my problem is reading multiple stl objets with serialization.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|