[serialization] serialization of an ifstream/ofstream class member
Hi. Do You know if there is a way to serialize an ifstream/ofstream class member. I have this class for example class Object { public: Object(); Object(string name); virtual ~Object(); string getName() const; private: string name_; ifstream file_; friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & name_; ar & file_; } }; when I try to serialize it throw compilation error : error: 'struct std::basic_ifstream<char>' has no member named 'serialize'. Is there a specific header i must include ?
On Fri, Mar 28, 2014 at 9:09 AM, Pablo Madoery
string name_; ifstream file_;
friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & name_; ar & file_; }
when I try to serialize it throw compilation error : error: 'struct std::basic_ifstream<char>' has no member named 'serialize'.
Is there a specific header i must include ?
May I ask what you intend to accomplish? A frequent use case for serializing memory data is to write it to the local filesystem. Presumably your ifstream represents a file that already exists on the filesystem. Maybe you want to record the file's name? Perhaps you want to record the current offset within that file? If so, I would serialize those things specifically.
That's what i was thinking about.
I Have a file in the filesystem that i am reading and I would like to
record the position I stop reading before I record the object that reads
the file, so when I de-serialize that object I could use it and continue
reading the same file in the recorded position.
How Do you think i can deal with this situation ?
Thank you
On Fri, Mar 28, 2014 at 10:51 AM, Nat Goodspeed
On Fri, Mar 28, 2014 at 9:09 AM, Pablo Madoery
wrote: string name_; ifstream file_;
friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & name_; ar & file_; }
when I try to serialize it throw compilation error : error: 'struct std::basic_ifstream<char>' has no member named 'serialize'.
Is there a specific header i must include ?
May I ask what you intend to accomplish? A frequent use case for serializing memory data is to write it to the local filesystem. Presumably your ifstream represents a file that already exists on the filesystem. Maybe you want to record the file's name? Perhaps you want to record the current offset within that file? If so, I would serialize those things specifically. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
{reordered the message chronologically}
2014-03-28 15:06 GMT+01:00 Pablo Madoery
On Fri, Mar 28, 2014 at 10:51 AM, Nat Goodspeed
wrote: On Fri, Mar 28, 2014 at 9:09 AM, Pablo Madoery
wrote: string name_; ifstream file_;
friend class boost::serialization::access; template<class Archive> void serialize(Archive & ar, const unsigned int version) { ar & name_; ar & file_; }
when I try to serialize it throw compilation error : error: 'struct std::basic_ifstream<char>' has no member named 'serialize'.
Is there a specific header i must include ?
May I ask what you intend to accomplish? A frequent use case for serializing memory data is to write it to the local filesystem. Presumably your ifstream represents a file that already exists on the filesystem. Maybe you want to record the file's name? Perhaps you want to record the current offset within that file? If so, I would serialize those things specifically.
That's what i was thinking about. I Have a file in the filesystem that i am reading and I would like to record the position I stop reading before I record the object that reads the file, so when I de-serialize that object I could use it and continue reading the same file in the recorded position. How Do you think i can deal with this situation ? Thank you
Hint: how would you write a copy constructor for your class? HTH, Kris
participants (3)
-
Krzysztof Czainski
-
Nat Goodspeed
-
Pablo Madoery