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