(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...
The data on VHS tapes, analog digital cameras, and television broadcasts is in analog format, so it must be converted into a digital data stream.
Answer the following statement true (T) or false (F)
In the accompanying figure, item 1 is pointing to the ____.
A. recently used programs B. search box C. Charms menu D. pinned items
Typing new text into a document at the insertion point is called ________ mode
Fill in the blank(s) with correct word
What is the squash and stretch animation technique?
The following questions are not in the student's Classroom in a Book. What will be an ideal response?