conversion of Cstring to BYTE

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

    I'm fairly certain Jay is correct for your first question. You need to include the right header.

    For your second question, why would you expect that code to work? Let's walk through what the code you've written actually does.

    1. Create a char pointer (char *) without initializing it. This leaves lpData/lpBuffer pointing to a random location in memory.
    2. Create a CString and initialize it with this random pointer.
    3. Extract the buffer from the CString and compare it to a string literal.

    Keeping in mind that the CString contains random garbage, what exactly do you expect this code to do? (Other than crash horribly? =) )

    I also want to point out that you need to be more consistent in your approach to strings. Do you plan to support both char and wchar_t based strings as your use of TCHAR in the first sections suggests? Do you want to work with C-Style strings or do you want to use objects like CString? If you want to work with CString's, just use the Compare function that CString provides. Don't bother with strcmp.

提交回复
热议问题