I have unsigned char*, want to convert it to std::string. Can you please tell me the safest way to do this?
I have unsigned char* , want to convert it to std::string . Can you
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You just needed to cast the
unsigned charinto acharas thestringclass doesn’t have a constructor that acceptsunsigned char:However, you will need to use the length argument in the constructor if your byte array contains nulls, as if you don’t, only part of the array will end up in the string (the array up to the first null)