【问题标题】:Converting UINT to WS_STRING将 UINT 转换为 WS_STRING
【发布时间】:2017-03-06 02:18:46
【问题描述】:

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

【问题讨论】:

    标签: c++ wcf int const-cast


    【解决方案1】:

    This answer 已经展示了如何将std::wstring 转换为WS_STRING

    您已经知道如何将数字转换为std::wstring

    int i = 100;
    std::wstring iStr = std::to_wstring(i);
    

    因此,只需使用iStr 作为链接答案中提供的解决方案的输入即可。

    提示:将d 替换为iStr,将url 替换为responseWsString

    【讨论】:

      猜你喜欢
      • 2015-02-05
      • 1970-01-01
      • 2013-03-05
      • 2012-11-06
      • 2014-07-31
      • 2016-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多