テキスト ファイルを読み取らなければなりません。ただし、特定のテキスト ファイルの 1 つが問題を引き起こしています。テキスト ファイルが巨大 (電子ブック全体) であるだけでなく、いくつかのアクセント付きの文字もあります。適切な句読点またはスペースで停止して、一度に 1 文字ずつ単語を読み込んでいます。これを行うには、文字やアポストロフィなどの句読点に適切な ASCII をテストします。アクセント付きの文字も読むことができますが、他の文字とは分けておく方法はありますか? ランダムなライブラリを追加する必要がありますか?
単語を取得するための私のコードは次のとおりです。
string GetNextWord(){
string w=""; // used to store each word temporarly
char c; // used for each individual character
int i=0; // a counter
input.get(c); // gets first character
c=tolower(c); // forces c to lowercase
while(c>=97 && c<=122 || c==39){ // loops while the character is a lowercase letter or '
w=w+c; // adds character to word string
input.get(c); // gets next character
c=tolower(c); // forces c to lowercase
++i; // increments counter
}
if(i>0) // if there is a word
return w; // return the word
else // otherwise string is NULL
return "NOT A WORD!"; // returns a flag to main
}
これを除く、これまでのすべてのファイルで動作します。
ここで入力を確認できます-> http://www.gutenberg.org/cache/epub/244/pg244.txt