how to convert char array to wchar_t array?

后端 未结 3 2019
情书的邮戳
情书的邮戳 2020-12-10 14:27
char cmd[40];
driver = FuncGetDrive(driver);
sprintf_s(cmd, \"%c:\\\\test.exe\", driver);

I cannot use cmd in

sei.lpF         


        
3条回答
  •  無奈伤痛
    2020-12-10 15:00

    From MSDN:

    #include 
    #include 
    #include 
    
    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;
    }
    

提交回复
热议问题