正如标题所示,我想知道将inta 转换为a 的最佳方法const wchar_t*.实际上我想使用这个_tcscpy功能
_tcscpy(m_reportFileName, myIntValue);
Run Code Online (Sandbox Code Playgroud)
由于您使用的是C方法(我假设它m_reportFileName是一个原始 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);
}
Run Code Online (Sandbox Code Playgroud)
在更现代的C++方法中,您可以考虑使用std::wstring而不是原始wchar_t数组和std::to_wstring转换.
在C++11:
wstring value = to_wstring(100);
Run Code Online (Sandbox Code Playgroud)
预C++11:
wostringstream wss;
wss << 100;
wstring value = wss.str();
Run Code Online (Sandbox Code Playgroud)