c++ - 将 UINT 转换为 WS_STRING

标签 c++ wcf int const-cast

我正在用非托管代码编写对 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/

相关文章:

c# - 使用 IsOneWay 属性的 WCF 问题

java - 如何在 if else 语句中表达一系列整数?

python - 定义变量类型! PYTHON

c++ - InternetOpenUrl 仅在下载整个 HTTP 响应后返回

c++ - SDL2 IMG_Load 不工作

c++ - glm::mat4 * glm::mat4 产生不正确的结果?

assembly - 如何在汇编中将有符号 8 位字节转换为有符号 16 位整数?

c++ - boost::phoenix 用作仿函数时的错误消息

asp.net-mvc - 网络农场中的 nHibernate 策略

WCF 路由备份列表 - 使用时记录