+ 1
Reversing a string c++
So in this case, the goal is to take a string,and output the string but reversed. how I've attempted to do this is to place the letters of the original string into a char array. which worked. but where it went wrong was I am trying to concatenate the contents of the array, into a string that will be the reversed version https://code.sololearn.com/cvaxwvq5hylt/?ref=app
6 Respostas
+ 3
#include <iostream>
using namespace std;
int main(){
string str = "abc";
for(int i=1;i <= str.size();i++){
cout<<str[str.size()-i];
}
return 0;
}
https://code.sololearn.com/ciWmy0p34SoH/?ref=app
+ 3
simple, use reverse function.
string str = "abcde";
// Reverse str[beign..end]
reverse(str.begin(),str.end());
cout << str;
//output- edcba
+ 3
you need to import "algorithm"
you can also refer to this.
http://www.geeksforgeeks.org/quickly-reverse-string-c/
+ 3
Shawn ist right
0
Iridescent995 is there some syntax you didn't specify? because it says something about it not being declared in the scope
0
I did import algorithm, or is it not #include <algorithm> and is something else