なぜこれが機能しないのか、私の人生では理解できません。ファイルから単語のリストの頻度チェックを行う必要があり、それらを読み取るときに、現在の単語を文字列配列の要素と照合してチェックしようとしています。それを追加します。コードは次のとおりです。
fin.open(finFile, fstream::in);
if(fin.is_open()) {
int wordArrSize;
while(!fin.eof()) {
char buffer[49]; //Max number chars of any given word in the file
wordArrSize = words.length();
fin >> buffer;
if(wordArrSize == 0) words.push_back(buffer);
for(int i = 0; i < wordArrSize; i++) { //Check the read-in word against the array
if(strcmp(words.at(i), buffer) != 0) { //If not equal, add to array
words.push_back(buffer);
break;
}
}
totNumWords++; //Keeps track of the total number of words in the file
}
fin.close();
これは学校のプロジェクト用です。コンテナー クラスを使用することは許可されていないため、char** 配列の展開、要素のプッシュ バックとポップアウトなどを処理する構造を構築しました。