C++ program to reverse a given string using predefined methods
codeaft.cpp
#include<iostream>
#include<bits/stdc++.h>usingnamespacestd;intmain(){cout<<"———————————————————————————————————————————";cout<<"\nProgram to reverse a given string";cout<<"\n———————————————————————————————————————————";strings;cout<<"\nEnter the string ";getline(cin,s);reverse(s.begin(),s.end());cout<<"\nThe reverse string is "<<s;cout<<"\n———————————————————————————————————————————\n";}
Output
codeaft@codeaft:~$ g++ codeaft.cpp codeaft@codeaft:~$ ./a.out
———————————————————————————————————————————
Program to reverse a given string
———————————————————————————————————————————
Enter the string Hello, World!
The reverse string is !dlroW ,olleH
———————————————————————————————————————————
codeaft@codeaft:~$
Dear User, Thank you for visitng Codeaft. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.