引数をファイル内のテキストと比較するプログラムで作業します(私のファイルは、多くの英語を含む辞書です)。2つの文字列を個別の文字で比較します。C++
現在、アプリケーションは完全に一致する文字列のみを処理します。
ファイル内の完全な文字列に入力された部分文字列を比較して一致させる方法があるかどうかを知りたがっていました。 例argがapの場合、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;
}
'ap'は' alliance'と一致する必要がありますか?次に、最初の文字を比較してください。それ以外の場合、[ここ](http://stackoverflow.com/questions/1878001/how-do-i-check-if-ac-string-starts-with-a-certain-string-and-convert-a-sub)あなたの複製物です。そして、その「eof」のこと...それとGoogleの代わりにやるべきことはしないでください。 – LogicStuff
std :: string :: compare()またはstd :: regex - eof()でループしません - https://latedev.wordpress.com/2012/12/04/all-about-eof/を参照してくださいなぜ –
あなたは[lenshtein-distance](https://en.wikipedia.org/wiki/Levenshtein_distance)のような寓意によって類似性を探しているのでしょうか? [Googleにはリンクがあります](http://www.google.com/search?q=levenshtein+distance+c%2B%2B) – LotPings