- 1
coding on how to reverse a word
2 Answers
+ 1
http://www.sololearn.com/app/cplusplus/playground/cLPV0Tjw08xz/
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
string word;
cout << "Enter a word to reverse: ";
cin >> word;
reverse(word.begin(), word.end());
cout << "Reversed word: " << word << endl;
return 0;
}
+ 1
A different way, without algorithm:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
cout << "Enter a string: ";
getline(cin, str);
for (int i = str.length() - 1; i >= 0; i--)
cout << str.at(i);
}