I am new here. Anyway. I am trying to search a word in a text file(which has 10 sentences) from a text file that consists of few keywords. Basically i am trying to find if one of the keywords in file2 consist in file1. I have tried but it seems like it compares by line instead of word. if anyone could help me with this? thanks.
int main()
{
bool Found;
int i = 0;
int j = 0;
string str;
ifstream file;
file.open("words.txt", ios::in | ios::binary);
string str2;
ifstream file2;
file2.open("M4.txt", ios::in | ios::binary);
while (!file.eof() && !Found) {
getline(file, str, ' ');
}
while (!file2.eof() && !Found) {
getline(file2, str2, ' ');
}
// if (str == str2)
if (file.get() == file2.get()) {
cout << "This order is valid. M3" << endl;
} else {
cout << "This order is invalid. M3" << endl;
}
system("pause");
return 0;
}
I hope anyone can help with this. Have stuck at here for weeks :(