/*
* @topic T0M291 Reverse string demo
* @brief Reverse characters using std::string and std::reverse
*/
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
int main()
{
using namespace std;
for (;;) {
cout << "Enter text to reverse: ";
string str;
// this does not allow to input spaces between wards:
//if (cin >> str) {
// this allows spaces in input:
if ( getline( cin, str ) ) {
// C++ standard library algorithm to reverse characters:
reverse( str.begin(), str.end() );
cout << "[" << str << "]\n";
} else {
break;
}
if (str == "tiuq") {
// user can type "quit" to exit program
break;
}
}//forever
system( "pause" );
return 0;
}