armin ariana
0
Q:

reverse string efficient in cpp without using function

#include <iostream>
using namespace std;
int main()
{
    char str[] = "Reverseme";
    char reverse[50];
    int i=-1;
    int j=0;
         /*Count the length, until it each at the end of string.*/ 
          while(str[++i]!='\0');
           while(i>=0)
                    reverse[j++]=str[--i];
            reverse[j]='\0';
      cout<<"Reverse of  a string is"<< reverse;
      return 0;
}
1
// A simple C++ program to reverse string using constructor  
#include <bits/stdc++.h>  
using namespace std;  
int main(){ 
  
    string str = "GeeksforGeeks"; 
  
    //Use of reverse iterators 
    string rev = string(str.rbegin(),str.rend()); 
  
    cout<<rev<<endl;  
    return 0; 
} 
1
// A quickly written program for reversing a string 
// using reverse() 
#include <bits/stdc++.h> 
using namespace std; 
int main() 
{ 
    string str = "geeksforgeeks"; 
  
    // Reverse str[begin..end] 
    reverse(str.begin(), str.end()); 
  
    cout << str; 
    return 0; 
} 
1

New to Communities?

Join the community