0

私は C++ でファイル処理に取り組んでいますが、削除できない奇妙なエラーが発生しています。ファイル処理に非常に慣れていないので、助けてください。

#include<iostream>
#include<string>
#include<fstream>
 using namespace std;

int main(void)
{
fstream index;
index.open("file1",ios::app);
index<<"this is the indexed file"<<endl;
index<<"file name /t"<<"size /t"<<"path"<<endl;
//index.close();

string line;
string wordtofind;
char filename[50];
int cnt;

//ifstream index("file1.txt");
if(index.is_open())
{
while(!index.eof())
{
getline(index,line);
cout<<line<<endl;
cout<<"enter a word to be searched"<<endl;
cin>>wordtofind;
cout<<"enter the file in which you want to search the given word"<<endl;
cin>>filename;
//cnt=count(filename,wordtofind);

    int counter=0;
    ifstream file;
    string word;

    file.open(filename);
    if(!file) //If not exist
    {
        cout << "Could not open file" << endl;

    }    
    else
    {
        while(file >> word)
        {   
            if(word.compare(wordtofind) == 0)
            counter++;
        }
    }
    file.close(); //always pays to be tidy



cout<<"the number of times the word occured in the file is "<<cnt<<endl;

index.close();
system("pause");
return 0;
}

エラー:

致命的なエラー C1075: 左中かっこ '{' の前にファイルの終わりが見つかりました

ありがとうございました!

4

3 に答える 3

3

これは通常、ブレースが閉じていないことを意味します。あなたの場合、while ループは中括弧で閉じられていません。また、ifステートメントを閉じていないと思います。

于 2011-03-30T06:19:23.393 に答える
2

閉じ中かっこが 2 つありません。あなたのコードは次の行で終わるべきだと思います:

            cout<<"the number of times the word occured in the file is "<<cnt<<endl;
        }
        index.close();
    }
    system("pause");
    return 0;
}
于 2011-03-30T06:25:22.217 に答える
1

cout<<"の後に1つの'}'が失われます。ファイル内で単語が出現した回数は"<

ちょうどこのような

} index.close();

于 2011-03-30T07:05:44.487 に答える