I can guess, you forgot to initialize your m
and n
variables with proper values.
Add m = 10; n = 5;
before calling Difference
and your code will work.
I also suggest you to write more readable code: better naming for variables, use some spaces and avoid global variables.
Edit:
In C++ you can write:
#include <algorithm>
#include <iostream>
#include <iterator>
#include <set>
int main() {
std::set<int> a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
std::set<int> b = { 1, 3, 5, 7, 9 };
std::set<int> c;
std::set_difference(a.begin(), a.end(), b.begin(), b.end(), std::inserter(c, c.begin()));
for (const auto item : c)
std::cout << item << " ";
return 0;
}
Detail information about std::set_difference
can be found here
4
solved How to perform A-B set operation in C program using builtin library