0

How can i convert const Byte* to std::string.I tried the following

std::string sTemp(reinterpret_cast<const char*>(ByteBuffer));

Where ByteBuffer is const Byte*.Not got the value of ByteBuffer in sTemp using the above code Please help

Thanks,

1
  • What is Byte? What do you mean by "not got the value"? Commented Mar 13, 2013 at 9:33

2 Answers 2

2

If ByteBuffer contains a NUL-terminated string, then the code should work fine.

If it doesn't, you need to supply its length as the second parameter to the string constructor.

The above assumes that Byte is what I think it is, and that ByteBuffer is not NULL.

Sign up to request clarification or add additional context in comments.

Comments

0

There's no such data type as 'Byte' in C++. I assume it's a 8-bit data store if at all it exists, in which case your code is correct. Make sure there's a null character - '\0' in the buffer.

2 Comments

BYTE, on the other hand, is defined by Windows.
Another thing to note is that BYTE will likely be an unsigned char.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.