简体   繁体   中英

How can I copy a CHAR Variable to WCHAR Variable in C++

I want to convert a CHAR file to UNICODE file. I read a file character by character in CHAR file type and then save this character in a CHAR Variable and then I want to copy this CHAR Variable to a WCHAR Variable and then I Write the the WCHAR Variable in to a UNICODE file.

here is the code :

#include<Windows.h>
#include<tchar.h>

int _tmain(int argc, LPCTSTR argv[])
{
    HANDLE hInfile, hOutfile;
    CHAR f1; 
    WCHAR f2;   
    DWORD Rd, Wrt; 
    INT i;
    CreateFile(argv[1], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL,NULL);
    CreateFile(argv[2], GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
    while ((ReadFile(hInfile, &f1, sizeof(CHAR), &Rd, NULL) && Rd>0)) 
    {
        **_tccpy(f2, f1);**
        WriteFile(hOutfile, &f2, Rd, &Wrt, NULL);
    }

    CloseHandle(hInfile);
    CloseHandle(hOutfile);

}

in bold code is the problem, how can I copy CHAR Variable to a WCHAR Variable. the _tccpy function and strcpy function cant do this, because the prototype of both of them is char or wachar.

Microsoft Specific Use wmain instead of main if you want to write portable code that adheres to the Unicode programming model.

wmain( int argc, wchar_t *argv[ ], wchar_t *envp[ ] )

wmain at ms http://msdn.microsoft.com/en-us/library/bky3b5dh(VS.80).aspx

在C ++中处理Unicode时,我总是发现这些字符串基础知识和转换非常有用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM