-
Notifications
You must be signed in to change notification settings - Fork 0
Converter
Gautier Lefebvre edited this page Feb 13, 2018
·
2 revisions
You can easily serialize objects to strings.
First, declare a method std::ostream& operator<<(std::ostream&, Foo&);
outside of your class.
Then you can convert it to a string in a single line:
Foo foo;
std::string s;
s = fwk::Converter::StringOf<Foo>(foo);
This works fine for basic types (int, float, etc.), but is not optimised for objects.
You can use this:
string s = "10";
uint32_t a;
a = fwk::Converter::StringTo<uint32_t>(s);
a = StringToUInt32(s); // #define of above
// a == 10;