(Reversing a string with Iterators) Write a program that inputs a line of text and prints the text backward. Use iterators in your solution.
What will be an ideal response?
```
// Program prints a string backward.
#include
#include
using namespace std;
int main()
{
string s;
cout << "Enter a string: ";
getline( cin, s, '\n' );
// reverse_iterator rd points to the beginning
// of the reversed string
string::reverse_iterator rb = s.rbegin();
// go to the end of the string
while ( rb != s.rend() )
{
cout << *rb; // dereference and print
++rb; // advanced one position
} // end while
cout << endl;
} // end main
```
Enter a string: print this backward
drawkcab siht tnirp
You might also like to view...
Name the three control structures.
What will be an ideal response?
You can determine whether an object has the property,prop, using thehasOwnProperty(prop)method.
Answer the following statement true (T) or false (F)