Assume proper includes have been executed, but not using directive or declaration. Write a definition of an iterator for a vector named vec of int values. Write a for loop that will display the contents vec on the screen, separated by spaces starting at the last element in the vector and proceeding to the first. Use iterators for the loop control.

What will be an ideal response?


```
#include
#include
using std::vector;
using std::cout;
using std::endl;

int main()
{
std::vector::reverse_iterator itr;
std::vector vec;

for(int i=0; i<10; i++)
vec.push_back(i);

for (itr = vec.rbegin(); itr != vec.rend(); itr++)
cout << *itr << " ";
cout << endl;
return 0;
}
```

The parts that are requested in the problem are in bold face. The std:: on vector is necessary to make this code work with VC++6.0 prior to patch level 5. This hack does not affect the program under Borland command line compiler 5.5.

Computer Science & Information Technology

You might also like to view...

A function written to handle operations involving one or more objects is a:

A. overloaded operator function B. operation function C. objective function D. class function

Computer Science & Information Technology

How do you combine data using joins?

What will be an ideal response?

Computer Science & Information Technology

A set of declarations grouped under one selector is called a declaration block

Indicate whether the statement is true or false

Computer Science & Information Technology

Word processing, presentation, and personal finance are types of personal interest applications.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology