- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to quickly reverse a string in C++?
In this section, we will see how to reverse a string very quickly using C++. For reversing there is a built-in function in the algorithm library, called reverse(). This function takes the beginning and the ending pointer of a container, then reverse the elements.
Input: A number string “Hello World” Output: “dlroW olleH”
Algorithm
Step 1:Take a string Step 2: reverse it using reverse() function Step 3: Print the result. Step 4: End
Example Code
#include<iostream> #include<algorithm> using namespace std; main() { string my_str = "This is a string to be reversed"; cout << "Initial state of this string: " << my_str << endl; //reverse using the reverse() function for reversing a string reverse(my_str.begin(), my_str.end()); cout << "Final state of this string: " << my_str; }
Output
Initial state of this string: This is a string to be reversed Final state of this string: desrever eb ot gnirts a si sihT
- Related Articles
- How to reverse a String using C#?
- Reverse a string in C#
- Reverse a string in C/C++
- How to Reverse a String in PL/SQL using C++
- C# program to reverse a string
- How to reverse a string in Python?
- Different methods to reverse a string in C/C++
- C# program to Reverse words in a string
- Reverse a String (Iterative) C++
- Reverse a String (Recursive) C++
- Reverse Words in a String in C++
- How to reverse a given string in Java?
- How to reverse a string in Python program?
- How to reverse String in Java?
- Reverse Vowels of a string in C++

Advertisements