Converting CLI array to std::string without for-cycle -
i want convert array<unsigned char>^
std::string
. possible conversion without iterating on array , assigning each character in string?
this "best" solution (and don't 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); (int = 0; < ilength; i++) strresult[i] = asource[i]; } return strresult; }
thanks opinions.
you can use string range constructor, , pin managed array.
pin_ptr<unsigned char> p = &asource[0]; unsigned char *unmanagedp = p; std::string str(unmanagedp , unmanagedp + asource->getlength(0));
or sequence constructor:
std::string str(unmanagedp , asource->getlength(0));
Comments
Post a Comment