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. 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::iterator itr;
std::vector vec;

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

for (itr = vec.begin(); itr != vec.end(); itr++)
cout << *itr << " ";
cout << endl;

return 0;
}
Explanation: 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...

Which of the following is NOT a protection for information that cryptography can provide?

A. redundancy B. availability C. integrity D. nonrepudiation

Computer Science & Information Technology

Which of the following functions rounds a number up or down to the number of digits indicated in the function?

A) ROUND B) ROUNDDOWN C) ROUNDUPDOWN D) ROUNDUP

Computer Science & Information Technology

Describe how you access a two-dimensional array value using two subscripts.

What will be an ideal response?

Computer Science & Information Technology

A ____ is a device that makes internetwork connections and provides routing between different WANs.

bridge gateway firewall domain name server

Computer Science & Information Technology