Working on a program that compares an argument to text in a file (my file being a dictionary containing a lot of english words).
Right now the application works only the strings match completely.
Wanted to know if there was a way to compare a partial string that is inputted to a complete string in the file and have it be a match. Example if the arg is ap, it'll match it to apple, application alliance ext.
# include <iostream>
# include <fstream>
# include <cstdlib>
# include <string>
using namespace std;
int main ( int argc, char *argv[] ) {
ifstream inFile;
inFile.open("/Users/mikelucci/Desktop/american-english-insane");
//Check for error
if (inFile.fail()) {
cerr << "Fail to Open File" << endl;
exit(1);
}
string word;
int count = 0;
//Use loop to read through file until the end
while (!inFile.eof()) {
inFile >> word;
if (word == argv[1]) {
count++;
}
}
cout << count << " words matched." << endl;
inFile.close();
return 0;
}