I'm trying to use std::vector
as a char
array.
My function takes in a void pointer:
void process_data(const void *data);
Before I simply just used this code:
char something[] = "my data here";
process_data(something);
Which worked as expected.
But now I need the dynamicity of std::vector
, so I tried this code instead:
vector<char> something;
*cut*
process_data(something);
The question is, how do I pass the char vector to my function so I can access the vector raw data (no matter which format it is – floats, etc.)?
I tried this:
process_data(&something);
And this:
process_data(&something.begin());
But it returned a pointer to gibberish data, and the latter gave warning: warning C4238: nonstandard extension used : class rvalue used as lvalue
.
vector<bool>
which is the exception to this answer (and doesn't have a contiguous memory storage ofbool
s). – Excretory