Reverse A String in C++ using reverse()

It’s always complicated when we try to solve difficult questions. However, stepping up with solving easy problems makes perfect sense. Strings can get extremely complicated as well as extremely easy. Therefore today we’re going to start with the easiest string question. That is to reverse a string in C++

Practising these types of questions also helps to get an upper edge in Competitive Programming. So open up your IDE and let’s get started real quick. Once you understand the logic practice this program on your own to make your brain work in a problem-solving way. This is a somewhat easy question so you might not get asked in an interview. But make sure to practice it on your own after reading this article.

 

What’s The Approach?

 

  • We will create a new string variable and will store the string which we want to reverse.

 

 

Also Read: Print Fibonacci Series using C++

 

C++ Program To Reverse A String

 

Input: TechDecodeTutorials

 

Output: slairotuTedoceDhceT

 

// A quickly written program for reversing a string
// using reverse()
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string str = "TechDecodeTutorials";

    // Reverse str[begin..end]
    reverse(str.begin(), str.end());

    cout << str;
    return 0;
}

 

Ethix

I'm a coding geek interested in cyberspace who loves to write and read

Leave a Reply

Your email address will not be published.