Merge Two Files Uniquely
hardQuestion 669Write a function int mergeUnique(const string& a, const string& b, const string& out) that reads two text files and writes a third one containing every distinct line from either input, sorted in ascending (dictionary) order, one per line, each followed by a newline. Duplicates, whether within one file or across both, appear only once. Return the number of lines written.
Both input files contain one word per line with no blank lines. Read each input with an fstream in ios::in mode using a getline loop, collect the lines in a set<string>, then open out in ios::out | ios::trunc mode and write the set.
The test creates the two input files, prints the returned count on its own line, then prints every line of the output file. For file a containing pear, apple and file b containing kiwi, apple it prints the output shown in Expected Output.
Do NOT write a main function.
Expected output
3 apple kiwi pear 3 ant cat dog
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...