how can i convert a string into a byte[] and them add the result using in a stream. THX. I am working in c++ code, ubuntu.
EDIT:
i have a std::string as a string value.
I need a method that takes as an input a std::string value and returns as an output the stream value.
You can get a pointer to the string buffer by simply calling
std::string.c_str(). That will return aconst char*(wherecharis anint8_t) that you can effectively use as abyte[]. Keep in mind though that the pointer returned is pointing to memory managed by the string object, so if you change anything in the original string class, you will invalidate the pointer. Also since it’s a pointer to aconst char, you shouldn’t change any values in the buffer. So if you need more permanent memory, or need a buffer you can modify, a better way to accomplish your goal would be to-do (using gcc, which shouldn’t be a problem since you’re on Ubuntu):Now use the
string_arrayas your memory buffer.If you need to return the buffer from a function, you’re going to have to allocate the buffer on the heap and return a pointer. That also means you’re going to have to call
delete []on the pointer as well after you’re done with it, or else you’re going to end up with a memory leak. So you could do the following: