Преобразование cstring в байт и сохранение его в локальном файле.
I want to convert the cstring to bytes and store it in a local file with size. The following code does not help. Just open the file and the string text is saved.
Что я уже пробовал:
CString str = "I am not sure that this method is right or not. Anyone can tell me how to convert a CString to BYTE* ?"; BYTE *pByte; int length = str.GetLength(); pByte = new BYTE[length + 1]; memcpy(pByte, (VOID*)LPCTSTR(str), length); str.ReleaseBuffer(); FILE *fp; if (fp = fopen("C:\\Users\\user\\mui0n.txt", "wb")) { fwrite(&length, sizeof(int), 1, fp); fwrite(pByte, length, 1, fp); } fclose(fp); delete[] pByte;