I want to convert array<unsigned char>^ to std::string. Is it possible to do the conversion without iterating over the array and assigning each character in string?
This is my "best" solution (and I don't like the assigning in for-cycle):
std::string CliArray2String(array<unsigned char>^ aSource)
{
std::string strResult("");
if (aSource != nullptr)
{
int iLength = aSource->GetLength(0);
strResult.reserve(iLength + 1);
for (int i = 0; i < iLength; i++)
strResult[i] = aSource[i];
}
return strResult;
}
Thanks for your opinions.
std::stringorstd::wstring?strResultas a narrow-character string, but the return type is a wide-character string.std::string.