I dont know if i did it right to make a new thread, because this is the same program
but another problem.
I got a problem with istream::getline.
If i use it without the delimiting character its gonna read the whole file so i cant compare word by word the 2 files.
If i use the delimiting character ' ' space, it wont take in consideration neither the last word of every line ,
because there is know 'space' after it, nor the first word of every line, because there is no 'space' before it.
Maybe i should use another function like read() or something?
Thanks for any input on this.
Code:
int main ()
{
vector<string> vWords1;
vector<string> vWords2;
read_file("1.txt", vWords1);
read_file("2.txt", vWords2);
sort (vWords1.begin(), vWords1.end());
sort (vWords2.begin(), vWords2.end());
vector<string> v;
set_intersection (vWords1.begin(), vWords1.end(), vWords2.begin(), vWords2.end(), back_ inserter(v));
cout << "Intersection has " << v.size() << " elements.\n";
for (size_t i = 0; i != v.size(); ++i)
cout << "The "<< i+1 <<"." << " element is: " << v[i] << "\n";
system("pause");
}
void read_file(const char* name, vector<string>& vWords)
{
ifstream file(name);
string line;
vWords.clear();
while (getline(file, line, ' ')) {
vWords.push_back(line);
}
}