I rewrote the code but im having trouble defining the InputIterator1 first1, InputIterator1 last1 members when using strings with set_intersection.
Code:
void read_file(const char*, set<string>& );
int main ()
{
set<string> sWords1;
set<string> sWords2;
read_file("1.txt", sWords1);
read_file("2.txt", sWords2);
vector<string> v;
vector<string>::iterator it;
it = set_intersection (sWords1, sWords1.size(), sWords2, sWords2.size(), v.begin()); // having trouble here
cout << "Intersection has " << int(it - v.begin()) << " elements.\n";
for (size_t i = 0; i != v.size(); ++i)
cout << "The "<< i+1 <<"." << " element is: " << v[i] << "\n";
system("pause");
return 0;
}
void read_file(const char* name, vector<string>& vWords)
{
ifstream file(name);
string line;
vWords.clear();
while (getline(file, line, ' ')) {
vWords.push_back(line);
}
}