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...

To make a comment line in VBA, start the line with ________

Fill in the blank(s) with correct word

Computer Science & Information Technology

You cannot use a function to conditionally format cells.? ____________________

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

Computer Science & Information Technology