I think I'd use std::set - cppreference.com
Read the first file into set 1.
When reading the 2nd file, do one of two things
- if it's in set1, it's common to both (so remove it from set1)
- otherwise, add it to set2
The end result is two sets containing only items that appear in one file.