## Elixir42

Its true you have to make an effort on your own behalf. But here is the sugar you are after. Read boost.Serialization
(All of it!) and here is how to write and read - you can choose whether you want binary or text. Let me know if you need more help.

#include <iostream>
#include <fstream>
#include <boost\archive\xml_iarchive.hpp>    // XML In
#include <boost\archive\xml_oarchive.hpp>    // XML Out
#include <boost\archive\text_iarchive.hpp>   // Text In
#include <boost\archive\text_oarchive.hpp>   // Text Out
#include <boost\archive\binary_iarchive.hpp> // Binary In
#include <boost\archive\binary_oarchive.hpp> // Binary Out

int main()
{

{
// ofstream ofs("filename.txt", std::ios::trunc);
ofstream ofs("filename.bin", std::ios::binary);

//boost::archive::xml_oarchive oa(ofs, iFlags);
//boost::archive::text_oarchive oa(ofs, iFlags);
boost::archive::text_oarchive oa(ofs, iFlags);
int i = 42;
string s = "hello";
oa << i << s;
}
{
ifstream ifs("filename.bin", std::ios::binary);

//boost::archive::xml_iarchive ia(ifs, iFlags);
//boost::archive::text_iarchive ia(ifs, iFlags);
boost::archive::text_iarchive ia(ifs, iFlags);
int i = 9;
string s;
ia >> i;
ia >> s;
cout << i << " " << s.c_str();
}

cin.get();
return 0;
}

It writes an integer and a string then reads it from a binary file. Read in the same way you have written out. I hope it starts you out on the right path.