conversion of Cstring to BYTE

后端 未结 5 2006
被撕碎了的回忆
被撕碎了的回忆 2021-01-14 06:08

I am using Visual Studio c++ and want to convert the Cstring to Byte. I have written this code but it gave me error in the second line that \"data\" is undefined.

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-14 06:42

    Make sure you include atlstr.h to provide the definition of CString, as below:

    #include "stdafx.h"
    #include 
    #include 
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        CString data = _T( "OK");
        LPBYTE pByte = new BYTE[data.GetLength() + 1];
        memcpy(pByte, (VOID*)LPCTSTR(data), data.GetLength());
        return 0;
    }
    

提交回复
热议问题