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.
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; }