What will happen when you attempt to compile and run the following code?

Last Updated on May 22, 2022 by Admin 2

What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main()
{
   int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
   
   vector<int> v(mynumbers, mynumbers+7);

   set<int> s1(v.begin(),v.end());

   s1.insert(v.begin(),v.end());

   s1.insert(v.begin(),v.end());//LINE I

   set<int>::iterator found = s1.find(9);

   for (; found!=s1.end(); ++found)

      cout << *found <<", ";
   return 0;
}
  • program outputs: 9, 0, 2, 1, 4, 5,
  • program outputs: 3, 9, 0, 2, 1, 4, 5,
  • code will not compile
  • the exception will be thrown at line LINE I
  • program outputs:9,
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments