How to convert LPBYTE to string

1.3k Views Asked by At
LPBYTE buffer = (LPBYTE)calloc(1024, sizeof(char));
std::string res;

I want something like:

res = buffer;
1

There are 1 best solutions below

2
Ted Lyngmo On BEST ANSWER

You can use the std::string constructor (number 6 in the link) that uses iterators to copy the buffer into a string:

std::string res(buffer, buffer + 1024);

Note that there is no conversion other than the unsigned chars in your buffer being converted to chars in the std::string.