Last Updated on May 22, 2022 by Admin 2
What will happen when you attempt to compile and run the following code?
#include <vector> #include <set> #include <iostream> #include <algorithm> using namespace std; void print (int v) { cout << v << ", "; } struct Sequence { int start; Sequence (int start):start (start) { } int operator () () { return start++; } }; bool predicate (int v) { return v % 2 == 0; } int main() { vector < int > v1 (7); generate_n (v1.begin(), 7, Sequence (1)); //LINE I remove_if(v1.begin (), v1.end(), predicate); //LINE II for_each(v1.begin (), v1.end(), print); return 0; }
- runtime error at LINE I
- runtime error at LINE II
- compilation error in LINE II
- the program outputs
1, 3, 5, 7,
- you can’t call
remove_if
function on set - the program outputs
1, 3, 5, 7, 5, 6, 7,
- the program outputs
2, 4, 6,
- compilation error in LINE I