开发者

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

开发者 https://www.devze.com 2023-02-26 05:17 出处:网络
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开发者_StackOverf

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开发者_StackOverflow社区 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


I have always found these string basics and conversions very useful when dealing with Unicode in C++.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号