我正在用非托管代码编写对 WCF 调用的响应。问题是我有一个整数,我想将其转换为 WS_STRING
并回应。
std::towstring
仅转换为 wstring 而不会转换为 WS_STRING。我怎样才能做到这一点?
我看到有一个较旧的线程有类似的问题,但似乎没有答案。
int i = 100;
responseWsString = std::to_wstring(i);
//Throws compiler error : No operator '=' matches operands of type WS_STRING = std::wstring
这是预期的,因为类型不同。另一个线程提到 const_cast<>
不是一个好方法。那么我该如何解决这个将 int 转换为 WS_STRING 的简单问题呢?
这是上一篇的链接: Convert wstring to WS_STRING
最佳答案
This answer已经展示了如何将 std::wstring
转换为 WS_STRING
。
您已经知道如何将数字转换为 std::wstring
:
int i = 100;
std::wstring iStr = std::to_wstring(i);
因此,只需使用 iStr
作为链接答案中提供的解决方案的输入即可。
提示:将d
替换为iStr
,将url
替换为responseWsString
。
关于c++ - 将 UINT 转换为 WS_STRING,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42616527/