The following line is in error:
std::ofstream ofs("c:\test");
The compiler would've spit out a warning (at least) if your file was called jest
; but '\t'
-- being the escape for inserting a tab, your error goes by uncaught. In short, the file will not be created. You can test this with:
if (ofs.good()) { ... }
Now, since the file was not created, you don't have a valid iterator to pass on to boost::archive::text_oarchive
which throws the exception.
Try this:
std::ofstream ofs("c:\\test");
// --^ (note the extra backslash)
if (ofs.good()) {
boost::archive::text_oarchive oa(ofs);
// ...
}
Hope this helps!
PS: A final nit I couldn't stop myself from making -- if you are going to use
using namespace std;
then
ofstream ofs("c:\\test");
is good enough. Of course, it is not an error to qualify ofstream
, but it would not be the best coding style. But then, you know using using namespace
is bad, don't you?
PPS:Thank you -- sharptooth
for reminding me that \t
gets you a tab!