You could try:
std::stringstream ss;
std::string uuidStr;
boost::uuids::uuid uuid = boost::uuids::random_generator()();
ss << uuid;
ss >> uuidStr;
The Documentation states:
Stream Operators
The standard input and output stream operators << and >> are provided by including boost/uuid/uuid_io.hpp. The string representation of a uuid is hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh where h is a hexidecimal digit.
boost::uuids::uuid u1; // initialize uuid
std::stringstream ss;
ss << u1;
boost::uuids::uuid u2;
ss >> u2;
assert(u1, u2);
However the lexical_cast
should work as well.
Maybe you should check what uuid
actually contains to figure out if there's something wrong with the generated uuid
.
Also:
boost::uuids::uuid u; // initialize uuid
std::string s1 = to_string(u);
should be slightly faster according to the doc.