
I don't know is this is a bug as such, but thought I should bring it up. I boiled down an un handled exception I was receiving in VC 7.1 and related it to the demo.cpp The demo does not close or flush the ofstream before it reads back from the same file it wrote to, this appears to work correctly for the demo, but in the attached very simple case it does not. I am assuming that it is because the ofstream did not get flushed and the file contains no data. I think that adding a flush or close would make the demo more robust and complete. int _tmain(int argc, _TCHAR* argv[]) { std::string filename(boost::archive::tmpdir()); filename += "/demofile.txt"; std::string b1("mike"); std::ofstream ofs(filename.c_str()); boost::archive::text_oarchive oa(ofs); oa << b1; // FIX ofs.flush(); ofs.close(); // Without either of these VC7.1 gives // Unhandled exception at 0x77e738b2 in bstTest.exe: Microsoft C++ exception: // boost::archive::archive_exception @ 0x0012f7bc. " // END FIX std::string b3; std::ifstream ifs(filename.c_str()); boost::archive::text_iarchive ia(ifs); ia >> b3; } Call stack -> bstTest.exe!boost::throw_exception<boost::archive::archive_exception>(co nst boost::archive::archive_exception & e={...}) Line 40 C++ bstTest.exe!boost::archive::detail::common_iarchive<boost::archive::text _iarchive>::init() Line 69 + 0x31 C++ bstTest.exe!boost::archive::text_iarchive_impl<boost::archive::text_iarc hive>::text_iarchive_impl<boost::archive::text_iarchive>(std::basic_istr eam<char,std::char_traits<char> > & is={...}, unsigned int flags=0x00000000) Line 70 C++ bstTest.exe!boost::archive::text_iarchive::text_iarchive(std::basic_istr eam<char,std::char_traits<char> > & is={...}, unsigned int flags=0x00000000) Line 82 + 0x33 C++

Possible Serialization demo.cpp issue.Its my custom to use scoping for automatic closing of streams and archives. With this, your example would look more like: int _tmain(int argc, _TCHAR* argv[]) { std::string filename(boost::archive::tmpdir()); filename += "/demofile.txt"; std::string b1("mike"); { std::ofstream ofs(filename.c_str()); boost::archive::text_oarchive oa(ofs); oa << b1; } // stream flushed and closed here. Then archive closed } This is the way its done in demo.cpp (by calling save/load in functions). Robert Ramey "Holmes, Michael A (Mike)" <mikeholmes@agere.com> wrote in message news:A58A470FA97DB74A9CC7687166D577E60BC3FE@pauex2ku08.agere.com... I don't know is this is a bug as such, but thought I should bring it up. I boiled down an un handled exception I was receiving in VC 7.1 and related it to the demo.cpp The demo does not close or flush the ofstream before it reads back from the same file it wrote to, this appears to work correctly for the demo, but in the attached very simple case it does not. I am assuming that it is because the ofstream did not get flushed and the file contains no data.
participants (2)
-
Holmes, Michael A (Mike)
-
Robert Ramey