C++ program to reverse a given string using predefined methods
kw.cpp
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cout<<"———————————————————————————————————————————";
    cout<<"\nProgram to reverse a given string";
    cout<<"\n———————————————————————————————————————————";
    string s;
    cout<<"\nEnter the string ";
    getline(cin, s);

    reverse(s.begin(), s.end());
    cout<<"\nThe reverse string is "<<s;
    cout<<"\n———————————————————————————————————————————\n";
}
Output
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out ——————————————————————————————————————————— Program to reverse a given string ——————————————————————————————————————————— Enter the string Hello, World! The reverse string is !dlroW ,olleH ——————————————————————————————————————————— kodingwindow@kw:~$
Advertisement