How to Make a Function That Takes String And Returns the String in Reverse Order C++

This is simple but logic building program in C++ about string. The function in the program prompt to enter the string and return the string in reverse order.

Source Code 

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<"\a\n\n\n"
<<"\t******************************************************"<<endl
<<"\t** **"<<endl
<<"\t** Welcome To **"<<endl
<<"\t** **"<<endl
<<"\t** String in reverse order **"<<endl
<<"\t** **"<<endl
<<"\t** Demo **"<<endl
<<"\t** **"<<endl
<<"\t******************************************************"<<endl
<<endl
<<endl;
cout<<"";

cout << "Enter your string: (Press Enter at the end)";
string string1;
getline(cin,string1,'\n');
for (int x = string1.size()-1; x >=0; x--){
cout << string1[x];
}

cout<<""<<endl;
cout<<""<<endl;
system("pause");
return 0;
}

Output of the Program

C++ program to reverse the string

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment