Reverse String in C++
Here is the source code for C++ program that reverses the input string...
For example: Input :"coder"
Output :"redoc"
Program
#include <iostream>
#include<cstdio>
using namespace std;
string FirstReverse(string str) { //Function to reverse string
string reverseString;
for(long i = str.size() - 1;i >= 0; --i){
reverseString += str[i];
}
return reverseString;
}
int main() {
string str;
cout<<"Enter some text: ";
cin>>str;
cout << FirstReverse(str)<<endl; //function call
return 0;
}
int main()
{
cout<<FirstReverse(gets(stdin))<<endl;
return 0;
}
Note: This is the first challenge program of coderbyte...
https://coderbyte.com
Well explained string operation .
ReplyDeletethere are good String program collection visit --->> Top String program