[uuid] to string problem
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.) -- H. Saygin Arkan Tampere University of Tech. CS / III - +358466646156
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.) see [1]http://www.boost.org/doc/libs/1_43_0/libs/uuid/uuid.html#b oost/uuid/uuid_io.hpp 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. References 1. http://www.boost.org/doc/libs/1_43_0/libs/uuid/uuid.html#boost/uuid/uuid_io....
11.05.2010 0:04, Andy Tompkins 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.) see http://www.boost.org/doc/libs/1_43_0/libs/uuid/uuid.html#boost/uuid/uuid_io.... one can also use lexical_cast eg: uuid u; string s = lexical_cast<string>(u); I'll update the documentation to include this example.
By the way. Andy, do you plan to implement to_string() member-function or standalone function? AFAIK lexical_cast has a lot of overhead :(
< snip >
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.)
see http://www.boost.org/doc/libs/1_43_0/libs/uuid/uuid.html#boost/uuid/uuid_io....
one can also use lexical_cast eg: uuid u; string s = lexical_cast<string>(u);
I'll update the documentation to include this example.
By the way. Andy, do you plan to implement to_string() member-function or standalone function? AFAIK lexical_cast has a lot of overhead :(
Hmm, I haven't really given it much thought. Since it doesn't need to be a member function, I would lean toward a standalone function. Do any other libraries have a similar function? I would likely create: template <typename C, typename T, typename A> std::basic_string<C, T, A> to_basic_string(boost::uuids::uuid const& u); as well as, std::string to_string(boost::uuids::uuid const& u); std::wstring to_wstring(boost::uuids::uuid conts& u); Regards, Andy.
On Tue, May 11, 2010 at 6:00 AM, Andy Tompkins <atompkins@fastmail.fm> wrote:
Hmm, I haven't really given it much thought. Since it doesn't need to be a member function, I would lean toward a standalone function. Do any other libraries have a similar function? I would likely create:
template <typename C, typename T, typename A> std::basic_string<C, T, A> to_basic_string(boost::uuids::uuid const& u);
as well as,
std::string to_string(boost::uuids::uuid const& u); std::wstring to_wstring(boost::uuids::uuid conts& u);
+1, unqualified call to to_string is how Boost Exception converts to string arbitrary objects stored in exception objects. If you use this form and someone adds a UUID to a boost::exception, it'll appear correctly in the output from boost::diagnostic_information. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
Emil Dotchevski skrev:
On Tue, May 11, 2010 at 6:00 AM, Andy Tompkins <atompkins@fastmail.fm> wrote:
Hmm, I haven't really given it much thought. Since it doesn't need to be a member function, I would lean toward a standalone function. Do any other libraries have a similar function? I would likely create:
template <typename C, typename T, typename A> std::basic_string<C, T, A> to_basic_string(boost::uuids::uuid const& u);
as well as,
std::string to_string(boost::uuids::uuid const& u); std::wstring to_wstring(boost::uuids::uuid conts& u);
+1, unqualified call to to_string is how Boost Exception converts to string arbitrary objects stored in exception objects. If you use this form and someone adds a UUID to a boost::exception, it'll appear correctly in the output from boost::diagnostic_information.
-1 a to_string() member is IMO much preferred for simplicity and the encapsulation perspective. Just like std::bitset<N>::to_string(). There seem to be no standard in Boost for this :-(, e.g. filesystem uses ::string(), format uses ::str(). -Thorsten
To turn back to my problem =) , Here's my method: string GeneratorUtils::getRandomID(){ random_generator gen; uuid u = gen(); //string str = boost::lexical_cast<string>(u); string str = boost::lexical_cast<char*>(u); return str; } And here's my test code: int main(){ cout << "SAYGIN" << endl; GeneratorUtils gen; cout << gen.getRandomID() << endl; return 0; } And here's the output: $ ~/DAIM_MPI_Correlation/utils$ g++ -c GeneratorUtils.cpp $ g++ -o test GeneratorUtils.cpp $ ./test SAYGIN terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_lexical_cast>
' what(): bad lexical cast: source type value could not be interpreted as target Aborted
Do you have any idea? On Wed, May 12, 2010 at 4:05 PM, Thorsten Ottosen <nesotto@cs.aau.dk> wrote:
Emil Dotchevski skrev:
On Tue, May 11, 2010 at 6:00 AM, Andy Tompkins <atompkins@fastmail.fm>
wrote:
Hmm, I haven't really given it much thought. Since it doesn't need to be a member function, I would lean toward a standalone function. Do any other libraries have a similar function? I would likely create:
template <typename C, typename T, typename A> std::basic_string<C, T, A> to_basic_string(boost::uuids::uuid const& u);
as well as,
std::string to_string(boost::uuids::uuid const& u); std::wstring to_wstring(boost::uuids::uuid conts& u);
+1, unqualified call to to_string is how Boost Exception converts to string arbitrary objects stored in exception objects. If you use this form and someone adds a UUID to a boost::exception, it'll appear correctly in the output from boost::diagnostic_information.
-1
a to_string() member is IMO much preferred for simplicity and the encapsulation perspective. Just like std::bitset<N>::to_string().
There seem to be no standard in Boost for this :-(, e.g. filesystem uses ::string(), format uses ::str().
-Thorsten
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- H. Saygin Arkan Tampere University of Tech. CS / III - +358466646156
sorry once more, I was trying with char* since I encountered with the previous problem, I forgot to change it. Now it produces uuid, that's really great I was able to make it at last =) thanks for your contributions... SA On Wed, May 12, 2010 at 4:30 PM, Saygin Arkan <saygenius@gmail.com> wrote:
To turn back to my problem =) , Here's my method:
string GeneratorUtils::getRandomID(){
random_generator gen; uuid u = gen();
//string str = boost::lexical_cast<string>(u); string str = boost::lexical_cast<char*>(u);
return str; }
And here's my test code:
int main(){ cout << "SAYGIN" << endl;
GeneratorUtils gen; cout << gen.getRandomID() << endl;
return 0; }
And here's the output: $ ~/DAIM_MPI_Correlation/utils$ g++ -c GeneratorUtils.cpp $ g++ -o test GeneratorUtils.cpp $ ./test SAYGIN terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_lexical_cast>
' what(): bad lexical cast: source type value could not be interpreted as target Aborted
Do you have any idea?
On Wed, May 12, 2010 at 4:05 PM, Thorsten Ottosen <nesotto@cs.aau.dk>wrote:
Emil Dotchevski skrev:
On Tue, May 11, 2010 at 6:00 AM, Andy Tompkins <atompkins@fastmail.fm>
wrote:
Hmm, I haven't really given it much thought. Since it doesn't need to be a member function, I would lean toward a standalone function. Do any other libraries have a similar function? I would likely create:
template <typename C, typename T, typename A> std::basic_string<C, T, A> to_basic_string(boost::uuids::uuid const& u);
as well as,
std::string to_string(boost::uuids::uuid const& u); std::wstring to_wstring(boost::uuids::uuid conts& u);
+1, unqualified call to to_string is how Boost Exception converts to string arbitrary objects stored in exception objects. If you use this form and someone adds a UUID to a boost::exception, it'll appear correctly in the output from boost::diagnostic_information.
-1
a to_string() member is IMO much preferred for simplicity and the encapsulation perspective. Just like std::bitset<N>::to_string().
There seem to be no standard in Boost for this :-(, e.g. filesystem uses ::string(), format uses ::str().
-Thorsten
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- H. Saygin Arkan Tampere University of Tech. CS / III - +358466646156
-- H. Saygin Arkan Tampere University of Tech. CS / III - +358466646156
On Wed, May 12, 2010 at 6:05 AM, Thorsten Ottosen <nesotto@cs.aau.dk> wrote:
Emil Dotchevski skrev:
On Tue, May 11, 2010 at 6:00 AM, Andy Tompkins <atompkins@fastmail.fm> wrote:
Hmm, I haven't really given it much thought. Since it doesn't need to be a member function, I would lean toward a standalone function. Do any other libraries have a similar function? I would likely create:
template <typename C, typename T, typename A> std::basic_string<C, T, A> to_basic_string(boost::uuids::uuid const& u);
as well as,
std::string to_string(boost::uuids::uuid const& u); std::wstring to_wstring(boost::uuids::uuid conts& u);
+1, unqualified call to to_string is how Boost Exception converts to string arbitrary objects stored in exception objects. If you use this form and someone adds a UUID to a boost::exception, it'll appear correctly in the output from boost::diagnostic_information.
-1
a to_string() member is IMO much preferred for simplicity and the encapsulation perspective.
A member function is incompatible with built-in types, so the question is how would you convert an int to string?
There seem to be no standard in Boost for this :-(, e.g. filesystem uses ::string(), format uses ::str().
This is another example why a member function is not practical, you can't have all 3rd-party types in the world agree on the name of a member function. However, you can provide a namespace-scope function overload for any type. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
or standalone function? AFAIK lexical_cast has a lot of overhead :(
Hmm, I haven't really given it much thought. Since it doesn't need to be a member function, I would lean toward a standalone function. Do any other libraries have a similar function? I would likely create:
template <typename C, typename T, typename A> std::basic_string<C, T, A> to_basic_string(boost::uuids::uuid const& u);
as well as,
std::string to_string(boost::uuids::uuid const& u); std::wstring to_wstring(boost::uuids::uuid conts& u);
How about making explicit specializations of lexical_cast that would be faster than the general implementation? That way the optimization is invisible. Also validate your assumptions that it is slow! I saw some code to format a number that ran it through iostreams, and thought why not use the standard ltoa (or whatever it was)? Turns out that the iostream way was much faster! It inlined everything and simplified the result. TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
On Tue, May 11, 2010 at 11:54 AM, John Dlugosz <JDlugosz@tradestation.com> wrote:
or standalone function? AFAIK lexical_cast has a lot of overhead :(
Hmm, I haven't really given it much thought. Since it doesn't need to be a member function, I would lean toward a standalone function. Do any other libraries have a similar function? I would likely create:
template <typename C, typename T, typename A> std::basic_string<C, T, A> to_basic_string(boost::uuids::uuid const& u);
as well as,
std::string to_string(boost::uuids::uuid const& u); std::wstring to_wstring(boost::uuids::uuid conts& u);
How about making explicit specializations of lexical_cast that would be faster than the general implementation? That way the optimization is invisible.
Nevermind optimizations, I think that a simple function call is easier to use and more practical: std::string x=to_string(y). Lexical_cast is in a different domain altogether IMO, plus it has other issues, for example it can't use ADL. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
How about making explicit specializations of lexical_cast that would be faster than the general implementation? That way the optimization is invisible.
Nevermind optimizations, I think that a simple function call is easier to use and more practical: std::string x=to_string(y). Lexical_cast is in a different domain altogether IMO, plus it has other issues, for example it can't use ADL.
Emil Dotchevski
hitting dictionary.com ... Anti-Defamation League? Activities of Daily Living? I like the idea of defining operator<< and being done with it. You can then use an easy-to-use wrapper to trigger it with all defaults (that would be lexical_cast), or a somewhat more verbose inline formatter that uses stringstreams, or the full ios library, as needed. If it's an explicit specialization, lexical_cast<string> is just another spelling for to_string. TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
On Tue, May 11, 2010 at 4:12 PM, John Dlugosz <JDlugosz@tradestation.com> wrote:
How about making explicit specializations of lexical_cast that would be faster than the general implementation? That way the optimization is invisible.
Nevermind optimizations, I think that a simple function call is easier to use and more practical: std::string x=to_string(y). Lexical_cast is in a different domain altogether IMO, plus it has other issues, for example it can't use ADL.
Emil Dotchevski
hitting dictionary.com ... Anti-Defamation League? Activities of Daily Living?
Argument-dependent look-up, but I'm sure that's not on dictionary.com :)
I like the idea of defining operator<< and being done with it.
The problem is that op<< needs a std::ostream, and that's not convenient when you want to convert something to string. However, calling op<< is a good default behavior for a generic to_string function template.
If it's an explicit specialization, lexical_cast<string> is just another spelling for to_string.
No, the important semantic difference is that lexical_cast<string> can not use ADL. However, it could be a good idea to write a generic lexical_cast<string> that resolves to a unqualified call to to_string. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
Argument-dependent look-up, but I'm sure that's not on dictionary.com :)
I'll add it to Wiktionary, but can't remember my password.
No, the important semantic difference is that lexical_cast<string> can not use ADL. However, it could be a good idea to write a generic lexical_cast<string> that resolves to a unqualified call to to_string.
Ah, to make the explicit specialization you would have to close the normal namespaces and open up the namespace for its primary template. But wait! It's not a specialization, it's an overloading. The template argument is for the result type. The parameter is overloaded in the normal way, and subject to normal resolution. to_string (const C& x) to_wstring (const C& x) to_xstring (const C& x) to_MFC_CString (const C& x) ... etc? to_string<std::wstring>(x); specifies the return type (which can default to std::string) and is defined in the same namespace as C. If you called it lexical_cast instead, are you saying that would not play nicely with the existing lexical_cast definitions? --John TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
On Wed, May 12, 2010 at 11:29 AM, John Dlugosz <JDlugosz@tradestation.com> wrote:
to_string<std::wstring>(x); specifies the return type (which can default to std::string) and is defined in the same namespace as C.
If you called it lexical_cast instead, are you saying that would not play nicely with the existing lexical_cast definitions?
Providing a function template parameter explicitly will disable ADL. To call lexical_cast<foo>(), you need to either qualify the call with the namespace name (so... is the foo overload of lexical_cast in the boost namespace or in foo's namespace?) or use using to bring a bunch of lexical_cast overloads in scope. Either way, it sucks. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
Providing a function template parameter explicitly will disable ADL.
I just looked through N3092, and that is not (no longer?) the case. f(x); // uses ADNL (f)(x); // suppresses ADNL f<int>(x); // still uses ADNL. §14.2 (temp.names, if you want to try finding the corresponding sections in an older standard) defines 'template-id' such that f<int> is one. §5.1.1 (expr.prim.general) defines a 'template-id' to be a 'unqualified-id'. §3.4.2 (basic.lookup.argdep) states "When the postfix-expression in a function call (5.2.2) is an unqualified-id, other namespaces not considered during the usual unqualified lookup (3.4.1) may be searched, and in those namespaces, namespace-scope friend function declarations (11.4) not otherwise visible may be found. These modifications to the search depend on the types of the arguments (and for template template arguments, the namespace of the template argument). I can't access my copy of the official C++98 standard anymore because of stupid DRM stuff in Acrobad Reader, and the paper copy is much harder to grep and has been consigned to a box somewhere for a few years. But maybe someone knows if that has changed and was indeed not the case before, or if the compiler is actually buggy now for not doing it? So, it is "the future" even if it is not the present. Default arg should still work, so making to_string be a template for different return types should be something that works as well as a single function now, is accessible the hard way if you want a different form, and will work better in the future. --John TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
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.)
see http://www.boost.org/doc/libs/1_43_0/libs/uuid/uuid.html#boost/uuid/uuid_io.... 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
ooopps, ok I forgot to include uuid_io.hpp file. Now it compiled... Thanks a lot for your helps. And about the discussions, I agree that there would be nice to have a function u.to_string() =) Saygin 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.)
see http://www.boost.org/doc/libs/1_43_0/libs/uuid/uuid.html#boost/uuid/uuid_io.... 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
-- H. Saygin Arkan Tampere University of Tech. CS / III - +358466646156
participants (6)
-
Andy Tompkins
-
Dmitry Vinogradov
-
Emil Dotchevski
-
John Dlugosz
-
Saygin Arkan
-
Thorsten Ottosen