Advertisement
Dani_info

reverse a string

Mar 28th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.23 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. using namespace std ;
  4.  
  5. string reverseString (string str )
  6. {
  7.     int n=str.length();
  8.     for (int i=0; i<n/2; ++i)
  9.       {  
  10.         swap (str[i], str[n-i-1]);
  11.       }
  12.       return str;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement