将 boost::uuid 转换为 char*

发布于 2024-09-13 13:21:00 字数 54 浏览 2 评论 0原文

我正在寻找将 boost::uuid 转换为 const char* 。转换的正确语法是什么?

I am looking to convert a boost::uuid to a const char*. What is the correct syntax for the conversion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

公布 2024-09-20 13:21:00

为了以防万一,还有 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();

Just in case, there is also boost::uuids::to_string, that works as follows:

#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();
病毒体 2024-09-20 13:21:00

您可以使用 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();

You can do this a bit easier using boost::lexical_cast that uses a std::stringstream under the hood.

#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();
喜爱皱眉﹌ 2024-09-20 13:21:00

您可以包含 ,然后使用运算符将​​ uuid 转换为 std::stringstream。从那里,它是根据需要到 const char* 的标准转换。

有关详细信息,请参阅Uuid 文档的输入和输出第二部分< /a>.

std::stringstream ss;
ss << theUuid;

const std::string tmp = ss.str();
const char * value = tmp.c_str();

(有关为什么需要“tmp”字符串的详细信息,请参阅在这里。)

You can include <boost/uuid/uuid_io.hpp> and then use the operators to convert a uuid into a std::stringstream. From there, it's a standard conversion to a const char* as needed.

For details, see 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();

(For details on why you need the "tmp" string, see here.)

千里故人稀 2024-09-20 13:21:00

您可以使用 boost/uuid/uuid_io.hpp 中的流函数。

boost::uuids::uuid u;

std::stringstream ss;
ss << u;
ss >> u;

You use the stream functions in boost/uuid/uuid_io.hpp.

boost::uuids::uuid u;

std::stringstream ss;
ss << u;
ss >> u;
轻拂→两袖风尘 2024-09-20 13:21:00
boost::uuids::uuid u;

const char* UUID = boost::uuids::to_string(u).c_str();

可以进行简单且快速的转换。

boost::uuids::uuid u;

const char* UUID = boost::uuids::to_string(u).c_str();

It is possible to do a simple and quick conversion.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文