JME
JME

Reputation: 2363

converting std::string to a uint8 *

I have a function that expects a uint8 * representing a buffer and an int representing the buffer length. How should I go about transforming a std::string into a uint8 * representing the string? I have tried using c_str() to transform it into a char * but I still can't convert to uint8 *.

The function signature looks like.

InputBuffer(const UINT8* buf, int len, bool usesVarLengthStreams = true)

and I am trying to do the following

string ns = "new value";
int len = 10;

UINT8 * cbuff = ns; //(UINT8 *) ns.c_str(); doesn't work

in = new InputBuffer(cbuff, len);

Upvotes: 1

Views: 6956

Answers (1)

Matt
Matt

Reputation: 6050

string.c_str() returns a (const char *) pointer, while UINT8 is:

typedef unsigned char UINT8; 

So the code should be:

const UINT8 * cbuff = static_cast<const UINT8 *>(ns.c_str());

Upvotes: 3

Related Questions