Well, if size is not a problem, one possible way to do this is to create an empty std::string , and then use reserve() to preallocate the potentially necessary space, and then add each char until you encounter '\0' .
std::string stdmystring; stdmystring.reserve(MyString_MAX_SIZE) ; for(size_t i=0;i<MyString_MAX_SIZE && MyString[i]!='\0';++i); stdmystring+=MyString[i];
reserve() guarantees you memory allocation, since you know max_size, and the string will never be anymore.
A call to the + = operator function will probably be inlined, but you still need to verify that the line has the required bandwidth, which is useless in your case. Infact it can be the same or worse than just using strlen to find the exact length of the string first so you can test it.
source share