文字列内の単語のスペルを修正するSpellCheckerというオブジェクトを作成しています。単語の綴りが正しいかどうかをチェックし、訂正しない場合は、行ごとに正しい単語のテキストファイルがあります。また、単語のテキストファイルのスペルが間違っていて、その訂正がタブで区切られています。私の問題はテキストファイルを読むことです。私はファイルが正常に開くかどうかを調べるためにif文を作成しましたが、私のファイルは読み込み可能でなければならないと信じています。私はなぜこれが起きているのかを探そうとしています。ここifstream C++を使用してテキストファイルを開くときにエラーが発生する11
は私のスペルチェッカーのコンストラクタはここ
SpellChecker::SpellChecker(string tempLanguage, string correctWordsFile,string wordCorectionsFile){
language=tempLanguage;
ifstream istream;
istream.open(correctWordsFile);
if(!istream.is_open()){
cout << "Error opening " << correctWordsFile << endl;
}
int count=0;
string temp;
while(!istream.eof()){
getline(istream,temp);
correctWords[count] = temp;
count++;
}
numCorrectWords = count;
istream.close();
istream.open(wordCorectionsFile);
if(!istream.is_open()){
cout << "Error opening " << wordCorectionsFile << endl;
}
int j=0;
int i=0;
char temp2;
while(!istream.eof()){
istream.get(temp2);
if(temp2 == '\t'){
j++;
}
else if(temp2 == '\n'){
i++;
j = 0;
}
else
wordCorections[i][j] += temp2;
}
numwordCorrections = i;
istream.close();
}
である私のメインです:事前に
int main(){
SpellChecker spellCheck("English","CorectWords.txt","WordCorections.txt");
spellCheck.viewCorrectWords();
spellCheck.viewCorrectedWords();
spellCheck.setEnd('~');
spellCheck.setStart('~');
cout << spellCheck.repair("I like to eat candy. It is greatt.");
}
ターミナルに戻り、 "CorectWords.txtを開くエラー"
感謝。
変数 "istream"を呼び出さないでください。 'std :: istream'があり、あなたの命名はこれと矛盾するかもしれません。 – PaulMcKenzie
ファイル名に絶対パス名を使用してみてください。 – Barmar