Cout a word backwards

+1 Adem Dinarević · September 19, 2014
Hello guys. I wanted to know if anyone knows the code for inputing a word, that outputs that word backwards? 

For example: tuna -----> anut or bucky ---------> <ykcub....

Post a Reply

Replies

Oldest  Newest  Rating
+1 Çağlan Turgut · September 19, 2014
There is a function for that in algorithm header: std::reverse. Here you go:
#include <algorithm>
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
    
   string input = ""; //I have created a string to get the input
   
   cout << "enter the word to reverse:" << endl;
   
   cin >> input;

   reverse(input.begin(), input.end());

   cout<<input;


}
0 Adem Dinarević · September 19, 2014
Thank you very much :D
  • 1

C++

106,966 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator