正如标题所示,我想知道将 a 转换int为 a的最佳方法const wchar_t*。实际上我想使用该_tcscpy功能
_tcscpy(m_reportFileName, myIntValue);
正如标题所示,我想知道将 a 转换int为 a的最佳方法const wchar_t*。实际上我想使用该_tcscpy功能
_tcscpy(m_reportFileName, myIntValue);
由于您使用的是C 方法(我假设这m_reportFileName是一个原始Cwchar_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++11:
wstring value = to_wstring(100);
前C++11:
wostringstream wss;
wss << 100;
wstring value = wss.str();
这不是“转换”。这是一个两步过程:
第一件事可以使用 eg 来完成StringCbPrintf(),假设您正在构建启用宽字符。
当然,您可以选择将字符串直接格式化为m_reportFileName,从而完全无需进行复制。
如果使用 wstring,可以考虑以下:
int ValInt = 20;
TCHAR szSize[20];
_stprintf(szSize, _T("%d"), ValInt);
wstring myWchar;
myWchar = (wstring)szSize;