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 source for Encrypt.
In C# I do
for (int i = 0; i < text.Length; i++) buffer[i] = (byte)text[i];
What I need to know is how to do the same but using unmanaged C++.
Thanks!
If you just need read-only access, then
c_str()will do it:If you need read/write access, then you can copy the string into a vector. vectors manage dynamic memory for you. You don’t have to mess with allocation/deallocation then: