c++ - 将 int 转换为 const wchar_t*

标签 c++

正如标题所示,我想知道将 int 转换为 const wchar_t* 的最佳方法。 其实我想用_tcscpy函数

_tcscpy(m_reportFileName, myIntValue);

最佳答案

由于您使用的是 C 方法(我假设 m_reportFileNameraw C wchar_t数组),您可能只想直接考虑 swprintf_s():

#include <stdio.h>  // for swprintf_s, wprintf

int main()
{
    int myIntValue = 20;
    wchar_t m_reportFileName[256];

    swprintf_s(m_reportFileName, L"%d", myIntValue);

    wprintf(L"%s\n", m_reportFileName);
}

在更现代的 C++ 方法 中,您可以考虑使用 std::wstring 代替原始 wchar_t 数组和 std::to_wstring用于转换。

关于c++ - 将 int 转换为 const wchar_t*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15109469/

相关文章:

c++ - 通过引用传递时隐式转换不起作用

c++ - 指向另一个类的方法的指针

c++ - 是否可以获取指向 Windows 7 中默认音频端点设备缓冲区的指针?

c++ - 确定一个数字是否包含用于类(class)分配的数字

c++ - “开始调试”在 Visual Studio 2005 中需要很长时间

c++ - 混合 std::wcout 和 std::cout 会出错,有什么问题吗?

c++ - 两个 AES 实现生成不同的加密结果

c++ - 从 boost::asio::io_service 中删除所有处理程序而不调用它们

C++ 链接和模板特化

c# - 未找到 native DLL