Get bytes from std::string in C++

后端 未结 7 1273
遇见更好的自我
遇见更好的自我 2020-12-08 14:12

I\'m working in a C++ unmanaged project.

I need to know how can I take a string like this \"some data to encrypt\" and get a byte[] array which I\'m gonna use as the

7条回答
  •  醉话见心
    2020-12-08 15:10

    If this is just plain vanilla C, then:

    strcpy(buffer, text.c_str());
    

    Assuming that buffer is allocated and large enough to hold the contents of 'text', which is the assumption in your original code.

    If encrypt() takes a 'const char *' then you can use

    encrypt(text.c_str())
    

    and you do not need to copy the string.

提交回复
热议问题