I've done exactly the same thing, using lexical. Here's my method:

string GeneratorUtils::getRandomID(){

    random_generator gen;
    uuid u = gen();

    string str = boost::lexical_cast<std::string>(u);

    return 0;
}

And I've received the errors belove.
I have 2 ideas about the problem:
1 - did I do something wrong while installing boost?
2 - did I do something wrong while compiling? I've just written g++ -c GeneratorClasses.h GeneratorClasses.cpp and after this command here's the output:

/usr/local/include/boost/lexical_cast.hpp: In member function ‘bool boost::detail::lexical_stream<Target, Source, Traits>::operator<<(const Source&) [with Target = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Source = boost::uuids::uuid, Traits = std::char_traits<char>]’:
/usr/local/include/boost/lexical_cast.hpp:1151:   instantiated from ‘Target boost::detail::lexical_cast(typename boost::call_traits<Source>::param_type, CharT*, size_t) [with Target = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Source = boost::uuids::uuid, bool Unlimited = true, CharT = boost::lexical_cast::char_type]’
/usr/local/include/boost/lexical_cast.hpp:1174:   instantiated from ‘Target boost::lexical_cast(const Source&) [with Target = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Source = boost::uuids::uuid]’
GeneratorClasses.cpp:93:   instantiated from here
/usr/local/include/boost/lexical_cast.hpp:595: error: no match for ‘operator<<’ in ‘((boost::detail::lexical_stream<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::uuids::uuid, std::char_traits<char> >*)this)->boost::detail::lexical_stream<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::uuids::uuid, std::char_traits<char> >::stream << input’
/usr/include/c++/4.4/ostream:108: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:117: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:127: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:165: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:169: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:173: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/bits/ostream.tcc:91: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:180: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/bits/ostream.tcc:105: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:191: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:200: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:204: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:209: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:213: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:221: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/ostream:225: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.4/bits/ostream.tcc:119: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]

On Mon, May 10, 2010 at 11:04 PM, Andy Tompkins <atompkins@fastmail.fm> wrote:
On Mon, 10 May 2010 14:26 +0300, "Saygin Arkan" <saygenius@gmail.com> wrote:
Hi,
I'm a newbie on boost.
I've downloaded and used some features.

I couldn't find how to cast uuid into string.

#include "boost/date_time/gregorian/gregorian.hpp"
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/uuid/string_generator.hpp>

...

date GeneratorUtils::getRandomDate() {
    int year, month ,day;
    day = rand() % 30;
    month = rand() % 12;
    year = 1980 + rand() % 25;
    string str_date = "" + day + month + year ;
    date d(from_simple_string(str_date));

    return d;

string GeneratorUtils::getRandomID(){

    random_generator gen;
    uuid u = gen();

    return u.uuid_to_string(); // ERROR
}


It does not accept any to_string() function. Is there a way to convert from uuid to string in C++?
(by the way, I can use the other things such as date d, uuid u etc.)
 
one can also use lexical_cast eg:
 
uuid u;
string s = lexical_cast<string>(u);
 
I'll update the documentation to include this example.
 
Regards,
Andy.

_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users



--
Saygin