我期待将boost :: uuid转换为const char *。什么是转换的正确语法?将boost :: uuid转换为char *
25
A
回答
36
你可以使用boost :: lexical_cast更简单一点,它使用std :: stringstream。
#include <boost/lexical_cast.hpp>
#include <boost/uuid/uuid_io.hpp>
const std::string tmp = boost::lexical_cast<std::string>(theUuid);
const char * value = tmp.c_str();
10
您可以包含<boost/uuid/uuid_io.hpp>
,然后使用操作员将uuid转换为std::stringstream
。从那里,这是根据需要标准转换为const char*
。
有关详细信息,请参见the Input and Output second of the Uuid documentation。
std::stringstream ss;
ss << theUuid;
const std::string tmp = ss.str();
const char * value = tmp.c_str();
(有关为什么需要 “TMP” 字符串的详细信息,see here。)
1
您在升压/ UUID/uuid_io.hpp使用流功能。
boost::uuids::uuid u;
std::stringstream ss;
ss << u;
ss >> u;
26
以防万一,也有boost::uuids::to_string
,该工作原理如下:
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
boost::uuids::uuid a = ...;
const std::string tmp = boost::uuids::to_string(a);
const char* value = tmp.c_str();
相关问题
- 1. 将char *转换为char? C++
- 2. 将Guid转换为Cassandra UUID
- 3. 将UUID转换为字节
- 4. boost :: interprocess ::字符串转换为char *
- 5. *将char转换为main并将* char转换为struct
- 6. char *转换为char *
- 7. 将char *转换为boost :: array for socket使用
- 8. 如何将boost :: filesystem :: directory_iterator转换为const char *
- 9. boost :: asio buffer无法将参数从char转换为const mutable_buffer&
- 10. 将Boost FileSystem3迭代器强制转换为const char *
- 11. 将NSString *转换为char?
- 12. 将char转换为字节
- 13. 将int转换为char
- 14. 将NSString转换为const char
- 15. 将char转换为int?
- 16. 将std :: vector转换为char *
- 17. 将wchar_t转换为char C++
- 18. 将char转换为short
- 19. 将char *转换为int
- 20. 将NSString转换为const char *
- 21. 将char []转换为off_t
- 22. 将宽CString转换为char *
- 23. 将char *转换为std :: vector
- 24. 将short int []转换为char *
- 25. 将char转换为ascii值
- 26. 将char转换为NSString
- 27. 将char转换为double
- 28. 将_TCHAR *转换为char *
- 29. 将Vector *转换为char *
- 30. C#将Char转换为KeyValue
对于人与古升压版本工作:这个方法在1.44介绍。见http://www.boost.org/doc/libs/1_43_0/boost/uuid/uuid_io.hpp http://www.boost.org/doc/libs/1_44_0/boost/uuid/uuid_io.hpp – user1556435 2016-02-17 14:44:01
This应该是正确的答案,恕我直言。 – 2016-06-22 18:36:52