← Back to STL Containers
Question 467
Elements Only in the First Set
Elements Only in the First Set
Write a functionset<int> difference(const set<int>& a, const set<int>& b)that returns a new set containing every value that is inabut not inb. Neither input set may be modified. The test prints the returned set's elements in ascending order separated by single spaces, or the wordemptyif the returned set has no elements. For example, witha= {1, 2, 3, 4} andb= {2, 4} the result is {1, 3}, printed as1 3. Do NOT write a main function.
Expected Output:
1 3 empty
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
STL ContainersSets
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.