Reverse string C++
reverse(str.begin(),str.end());
reverse string c++
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str;
getline(cin,str);
reverse(str.begin(),str.end());
cout<<str;
}
How to reverse a string in c++ with for loop
#include <iostream>
using namespace std;
int main() {
string greeting = "Hello";
int len = greeting.length();
int n=len-1;
for(int i=0;i<(len/2);i++){
//Using the swap method to switch values at each index
swap(greeting[i],greeting[n]);
n = n-1;
}
cout<<greeting<<endl;
}
How to reverse a string in c++ using reverse function
#include <iostream>
//The library below must be included for the reverse function to work
#include<bits/stdc++.h>
using namespace std;
int main() {
string greeting = "Hello";
//Note that it takes the iterators to the start and end of the string as arguments
reverse(greeting.begin(),greeting.end());
cout<<greeting<<endl;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us