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
std::vector
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.
You might also like to view...
The location of the reviewing pane cannot be changed
Indicate whether the statement is true or false
Match the following terms to their meanings:
I. Document version history II. No versioning III. Create major versions IV. Create major and minor versions V. Minor version A. Can provide disaster recovery options for unexpected content changes B. The default setting in SharePoint C. Documents are numbered with whole numbers and decimals D. Documents are numbered with whole numbers E. Draft version