如何将 char 数组转换为 wchar_t 数组?
char cmd[40];
driver = FuncGetDrive(driver);
sprintf_s(cmd, "%c:\test.exe", driver);
我不能在
sei.lpFile = cmad;
所以,如何将 char
数组转换为 wchar_t
数组?
so,
how to convert char
array to wchar_t
array ?
推荐答案
来自 MSDN:
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
using namespace System;
int main()
{
char *orig = "Hello, World!";
cout << orig << " (char *)" << endl;
// Convert to a wchar_t*
size_t origsize = strlen(orig) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
wchar_t wcstring[newsize];
mbstowcs_s(&convertedChars, wcstring, origsize, orig, _TRUNCATE);
wcscat_s(wcstring, L" (wchar_t *)");
wcout << wcstring << endl;
}
相关文章