Created
August 18, 2015 07:16
-
-
Save gwang/6d947057e527b33be3e3 to your computer and use it in GitHub Desktop.
reverse a string in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
using namespace std; | |
void reverse(string s) | |
{ | |
cout << "input = " << s << endl; | |
cout << "size = " << s.length() << endl; | |
for (int i = s.length()-1; i>=0; i--) cout << s[i]; | |
cout << endl; | |
} | |
int main(int argc, char **argv) | |
{ | |
string s; | |
cout << "Please enter the string to be reversed:" << endl; | |
getline(cin, s); | |
reverse(s); | |
// or we can just pass the string from the command line: | |
// cout << argv[1] << endl; | |
// reverse(argv[1]); | |
return (0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment