I've just been struggling with MSVC2005 to use the std::string(char*)
constructor just like the top-rated answer. As I see this variant listed as #4 on always-trusted http://en.cppreference.com/w/cpp/string/basic_string/basic_string , I figure even an old compiler offers this.
It has taken me so long to realize that this constructor absolute refuses to match with (unsigned char*)
as an argument ! I got these incomprehensible error messages about failure to match with std::string
argument type, which was definitely not what I was aiming for. Just casting the argument with std::string((char*)ucharPtr)
solved my problem... duh !