There's a ton of information available on overloading operator<<
to mimic a toString()
-style method that converts a complex object to a string. I'm interested in also implementing the inverse, operator>>
to deserialize a string into an object.
By inspecting the STL
source, I've gathered that:
istream &operator>>(istream &, Object &);
would be the correct function signature for deserializing an object of type Object
. Unfortunately, I have been at a loss for how to properly implement this - specifically how to handle errors:
- How to indicate invalid data in the stream? Throw an exception?
- What state should the stream be in if there is malformed data in the stream?
- Should any flags be reset before returning the reference for operator chaining?