I have a vector of chars (actually unsigned chars):
std::vector<unsigned char> vec;
I would like to cast it/ copy it to a string object. I have tried to do this in the following way:
std::string requestedName;
for (auto letter : vec)
{
requestedName.append((char)letter);
}
But compiller says that such conversion is not possible. I would aprichiate all help.
You can use the operator
+=
to perform this concatenationWorking demo
Also instead of concatenating in a loop, you can use the following overload of the
std::string
constructor