reverse string stl code example
Example 1: string reverse stl
int main() {
string str = "foobarbaz";
reverse(str.begin(), str.end());
cout << str; // prints "zabraboof"
return 0;
}
Example 2: std::reverse
std::vector<int> v{1,2,3};
std::reverse(std::begin(v), std::end(v));
Example 3: reverse string shwll
var="12345"
copy=${var}
len=${#copy}
for((i=$len-1;i>=0;i--)); do rev="$rev${copy:$i:1}"; done
echo "var: $var, rev: $rev"