Reverse a String in c++

Reverse a String in c++

#include <iostream>

using namespace std;

int main()
{
    string reverseString = "reverse";
    
    int lengthOfString = reverseString.length();
    
    for (int i = 0; i < lengthOfString/2; i++) {
        /* code */
        swap(reverseString[i] , reverseString[lengthOfString - i -1 ]);
        
    }
    
    std::cout << reverseString;

    return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *