I'm trying to use boost library to serialize std::map so that is possible to store it in a file. However I'm having so weird behaviours (i guess). So here is my code:
#include <map>
#include <fstream>
#include <iostream>
#include <bitset>
#include <boost/serialization/map.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
std::map<int,int> map = {{65,2}, {69,1}, {75,1} ,{77,1}, {82,1}, {84,2}, {89,2}};
void saveMapToFile(std::ofstream& f);
int main()
{
std::ofstream f("test.txt", std::ios::binary);
saveMapToFile(f);
std::cout << "position: " << f.tellp() << std::endl;
}
void saveMapToFile(std::ofstream& f)
{
std::cout << "position : " << f.tellp() << std::endl;
boost::archive::text_oarchive oarch(f);
std::cout << "position : " << f.tellp() << std::endl;
oarch << map;
std::cout << "position : " << f.tellp() << std::endl;
}
And here is the above code's output:
position : 0
position : 28
position : 75
position: 76
So can someone explain to me what is happening here? Why position after insterting map (in function) in different outside of it? I don't do any additional opperations, yet that pointer goes one byte further... Am I missing something? Thanks for your help in advance.