Boost logo

Boost Users :

From: Robert Ramey (ramey_at_[hidden])
Date: 2007-08-10 21:19:47


This is a known issue with C++ standard i/o. It is only related to
serialization
to the extent that serialization depends upon C++ standard i/o.

This comes up on a regular basis. I'm considering trappnig attempts to
serialize NaNs as errors - as I think they always are. But then I would
have
to document the trap and how to override it as opposed to adding to
the document why this is not a serialization issue.

Robert Ramey

Arnstein Ressem wrote:
> Hi,
>
> I have run into a problem with the boost xml serialization of
> overflowing floats. On Linux these are being serialized as 'inf' into
> the xml files, but when reading the float back in it results in stream
> errors. I have searched the archives to find an answer to this, but
> without luck. The small program below has been compiled and run on
> 32-bit and 64-bit Linux (RedHat Enterprise Linux 4) with boost 1.33.1
> and 1.34.1. In every case it results in a stream error and the float
> can not be read back in from the xml file.
>
> Does anyone know if this is supposed to work ?
>
> #include <fstream>
> #include <boost/archive/xml_iarchive.hpp>
> #include <boost/archive/xml_oarchive.hpp>
>
> int main()
> {
> const char fname[] = "float.xml";
>
> float f = 1.0e+20*1.0e+20;
>
> {
> std::ofstream ofs(fname);
> assert(ofs.good());
> boost::archive::xml_oarchive oa(ofs);
> oa << BOOST_SERIALIZATION_NVP(f);
> }
>
> {
> std::ifstream ifs(fname);
> assert(ifs.good());
> boost::archive::xml_iarchive ia(ifs);
> ia >> BOOST_SERIALIZATION_NVP(f);
> }
>
> return 0;
> }
>
> Best regards,
> Arnstein Ressem


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net