J
July
Hello all
Recentlly, I was asked to write a program in which there is a function
that need to reverse a std::string object.
I wrote like this:
string ReverseString(const string& srcStr)
{
string str;
for(size_t i = 0; i < srcStr.length(); ++i)
str += srcStr[srcStr.length() - i - 1];
return str;
}
Is there any potential error in the ReverseString function?
And if there is any more efficient approach to do this?
Recentlly, I was asked to write a program in which there is a function
that need to reverse a std::string object.
I wrote like this:
string ReverseString(const string& srcStr)
{
string str;
for(size_t i = 0; i < srcStr.length(); ++i)
str += srcStr[srcStr.length() - i - 1];
return str;
}
Is there any potential error in the ReverseString function?
And if there is any more efficient approach to do this?