Skip to content
Gautier Lefebvre edited this page Feb 13, 2018 · 2 revisions

Converter

Convert object to string

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);

Convert string to object

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;
Clone this wiki locally