Get bytes from std::string in C++

后端 未结 7 1249
遇见更好的自我
遇见更好的自我 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:15

    If you just need to read the data.

    encrypt(str.data(),str.size());
    

    If you need a read/write copy of the data put it into a vector. (Don;t dynamically allocate space that's the job of vector).

    std::vector<byte>  source(str.begin(),str.end());
    encrypt(&source[0],source.size());
    

    Of course we are all assuming that byte is a char!!!

    0 讨论(0)
提交回复
热议问题