c++boostuuidlexical-castboost-uuid

Boost compile error on converting UUID to string using boost::lexical_cast


I have this code which is based on several posts in SO:

boost::uuids::uuid uuid = boost::uuids::random_generator()();
auto uuidString= boost::lexical_cast<std::string>(uuid);

but when I am compiling this code, I am getting this error:

Source type is neither std::ostream`able nor std::wostream`able     C:\Local\boost\boost\lexical_cast\detail\converter_lexical.hpp  

How can I fix this error?


Solution

  • You're missing the include, I guess:

    Live On Coliru

    #include <boost/lexical_cast.hpp>
    #include <boost/uuid/uuid_io.hpp>
    #include <boost/uuid/uuid.hpp>
    #include <boost/uuid/random_generator.hpp>
    
    int main() {
        boost::uuids::uuid uuid = boost::uuids::random_generator()();
        auto uuidString = boost::lexical_cast<std::string>(uuid);
    }