c++ UUID到stl字符串
C++ UUID to stl string
尝试将UUID转换为字符串而不进行boost。我有以下内容,但将wszUuid分配给字符串guid不起作用。有人知道我怎么做,这样我就可以返回一个stl字符串吗?
string Server::GetNewGUID()
{
UUID uuid;
::ZeroMemory(&uuid, sizeof(UUID));
// Create uuid or load from a string by UuidFromString() function
::UuidCreate(&uuid);
// If you want to convert uuid to string, use UuidToString() function
WCHAR* wszUuid = NULL;
::UuidToStringW(&uuid, (RPC_WSTR*)&wszUuid);
if (wszUuid != NULL)
{
::RpcStringFree((RPC_CSTR*)&wszUuid);
wszUuid = NULL;
}
string guid;
guid = wszUuid; // ERROR: no operator "=" matches these operands operand types are: std::string = WCHAR*
return guid;
}
string Server::GetNewGUID()
{
UUID uuid = {0};
string guid;
// Create uuid or load from a string by UuidFromString() function
::UuidCreate(&uuid);
// If you want to convert uuid to string, use UuidToString() function
RPC_CSTR szUuid = NULL;
if (::UuidToStringA(&uuid, &szUuid) == RPC_S_OK)
{
guid = (char*) szUuid;
::RpcStringFreeA(&szUuid);
}
return guid;
}
使用wstring代替string。
wstring guid;
guid = wszUuid;
相关文章:
- 将stl字符串缩小到小于15个字符的容量
- 使用 char 分隔符解析C++中的字符串,但将可重复的字符保留为每个解析的子字符串 (C++ STL) 中的分隔符
- 如何使用 STL 算法将整数向量转换为字符串向量?
- 为什么 stl 字符串C++函数有时出错有时会出错?
- 在 stl 中的字符串中擦除关键字的工作?
- 有没有一种 STL 方法可以找到字符串的所有排列,给出一个以 C++ 为单位的大小?
- C++ wrt 字符串中的 STL 排序函数
- 将字符串流转换为 STL 容器
- 如何在不使用 STL 的情况下从函数反转字符串后返回字符串C++?
- 重新定义要在字符串的 STL 算法中使用的<运算符
- 从字符串(STL)中删除所有重复字符
- C++ STL 在逗号处拆分字符串
- 如何删除在没有STL的队列中存储在数组中的第一个字符串元素
- 寻找一种更有效的方法来使用 STL 函数检查字符串是否为回文
- C++STL字符串运算符+关联性
- 将字符串插入到c++stl集的时间复杂度
- 如何使用STL算法找到字符串中分隔两个不同字母的最短星号序列
- 使用stl替换嵌套的子字符串
- 循环访问字符串 (STL)
- c++转换成perl:如何使用c++11字符串STL函数