入力ファイルから一連の単語を 3 つの異なる文字列配列に読み込もうとしています。ファイル内の単語は「#」で区切られています。何らかの理由でコードが 2 回実行され、最初の配列は空白で、単語は . 助けてください、私のループは間違いなく間違っていて、何かを見落としているに違いありません。私が間違っていることを教えてください。ありがとう
Sample input file (input.txt)
complicated
insinuated
complex
juggernaut
#
blah
...
...
#
...
#include <iostream>
#include <fstream>
#include <string>
#include "conio.h"
using namespace std;
int main() {
ifstream inFile("dictionary.txt");
// Check for error
if (inFile.fail()){
cout << "Error Opening File." << endl;
exit(1);
}
string hard[27], medium[29], easy[33];
string getHardWord, getMedWord, getEasyWord;
int hardCount = 0, medCount = 0, easyCount = 0, delimitCount; // n is number of #
// delimiters and count is array position
// Read the dictionary file until the end of file
while (inFile){
inFile >> getHardWord;
while ((getHardWord != "#") && (delimitCount = 0)){
hard[hardCount] = getHardWord;
hardCount++;
inFile >> getHardWord;
}
delimitCount++;
cout << delimitCount << endl;
for (int iii = 0; iii < 27; iii++){
cout << hard[iii] << endl;
}
cout << endl;
inFile >> getMedWord;
while ((getMedWord != "#") && (delimitCount = 1)){
medium[medCount] = getMedWord;
medCount++;
inFile >> getMedWord;
}
delimitCount++;
cout << delimitCount << endl;
for (int jjj = 0; jjj < 27; jjj++){
cout << medium[jjj] << endl;
}
cout << endl;
inFile >> getEasyWord;
while ((getEasyWord != "#") && (delimitCount = 2)){
easy[easyCount] = getEasyWord;
easyCount++;
inFile >> getEasyWord;
}
delimitCount++;
cout << delimitCount << endl;
for (int kkk = 0; kkk < 27; kkk++){
cout << easy[kkk] << endl;
}
inFile.close();
}
_getch();
return 0;
}