Skip to content

Instantly share code, notes, and snippets.

@ygabo
Last active December 19, 2015 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ygabo/5983321 to your computer and use it in GitHub Desktop.
Save ygabo/5983321 to your computer and use it in GitHub Desktop.
Reverse string.
#include <iostream>
#include <string>
using namespace std;
void rev(string &x){
int j = x.length()-1;
for( int i = 0; i < x.length()/2; ++i){
swap(x[i], x[j--]);
}
}
int main(){
string d;
getline(cin, d);
cout << d << endl;
rev(d);
cout << d << endl;
cin.get();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment