This is a C++ program that demonstrates how to reverse a string using the std::swap function. The program works as follows:
Overall, this program demonstrates how to reverse a string in C++ by iterating over the first half of the string and swapping each character with its corresponding character in the second half of the string.
#include<iostream> #include<string.h> using namespace std; int main() { int i,n; string str = "TutorJoes"; n=str.length(); for (i=0;i<n/2;i++) { swap(str[i],str[n-i-1]); } cout<<"\nAfter reversing string"<<str; return 0; }To download raw file Click Here
After reversing string seoJrotuT
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions