conversion of Cstring to BYTE

后端 未结 5 1990
被撕碎了的回忆
被撕碎了的回忆 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 07:00

    Probably you didn't include the cruicial header

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

    This code works fine.

提交回复
热议问题