Double null-terminated string

后端 未结 2 1875
野性不改
野性不改 2021-01-05 02:57

I need to format a string to be double null-terminated string in order to use SHFileOperation.

Interesting part is i found one of the following working, but not both

2条回答
  •  星月不相逢
    2021-01-05 03:14

    You cannot use CString for this purpose. You will need to use your own char[] buffer:

    char buf[100]; // or large enough
    strcpy(buf, "string to use");
    memcpy(buf + strlen(buf), "\0\0", 2);
    

    Although you could do this by only copying one more NUL byte after the existing NUL terminator, I would prefer to copy two so that the source code more accurately reflects the intent of the programmer.

提交回复
热议问题