60.9k views
3 votes
For the block of C++ code to work (shown below), which header file(s) is (are) needed.

int main()
vector v;
vector :: iterator p;
for (int i = 0; i <= 99; i++)
v.push_back(i);
sort(v.begin(), v.end());
A. #include
B. #include
C. #include
D. #include and #include
E. #include and #include

1 Answer

4 votes

Final answer:

The C++ code requires the and header files to provide the necessary definitions for the vector and sort function. The correct answer is D.

Step-by-step explanation:

The C++ code in the question uses a vector and a sorting function. To ensure that the code works properly, specific header files need to be included that provide the definitions for these elements. For this block of code, the following header files are required:

  1. <vector> - This is needed for using the vector container.
  2. <algorithm> - This provides the sort function used to sort the elements of the vector.

So the correct answer is:
D. #include <vector> and #include <algorithm>

User Akshay Phulare
by
8.1k points