You have a few memory problems with your attempt, as well as a logical one. All you need to return a copy of a string with the characters being upper case is:
std::string str = "My Original string";
std::string myCopy(str);
std::locale loc;
std::transform(myCopy.begin(), myCopy.end(), myCopy.begin(), [&](char c)
{
return std::toupper(c, loc);
});