Question: home / study / engineering / computer science / computer science questions and answers / a. the following code from cplusplus.com illustrates 5 different vector

home / study / engineering / computer science / computer science questions and answers / a. the following code from cplusplus.com illustrates 5 different vector constructors available ... Question: A. The following code from cplusplus.com illustrates 5 different vector constructors available in... A. The following code from cplusplus.com illustrates 5 different vector constructors available in the STL. Write a test program that uses all 5 constructors and demonstrates the use of the following vector functions / operators: assign, at, back, begin, capacity, clear, empty, end, erase, front insert, max_size, =, [], pop_back, push_back, size.

// constructing vectors #include #include

int main () { // constructors used in the same order as described above: std::vector first; // empty vector of ints std::vector second (4,100); // four ints with value 100 std::vector third (second.begin(),second.end()); // iterating through second std::vector fourth (third); // a copy of third

// the iterator constructor can also be used to construct from arrays: int myints[] = {16,2,77,29}; std::vector fifth (myints, myints + sizeof(myints) / sizeof(int) ); std::cout << "The contents of fifth are:"; for (std::vector::iterator it = fifth.begin(); it != fifth.end(); ++it) std::cout << ' ' << *it; std::cout << ' '; return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!