swap first and last character of string in c++ code example Example: swap first and last character of string in c++ std::swap(str.front(), str.back());