Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
处理文件时出现致命错误 我正在处理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; } #包括 #包括 #包括 使用名称空间std; 内部主(空) { fstream指数; index.open(“file1”,ios::app); 索引_C++_File_File Handling - Fatal编程技术网

处理文件时出现致命错误 我正在处理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; } #包括 #包括 #包括 使用名称空间std; 内部主(空) { fstream指数; index.open(“file1”,ios::app); 索引

处理文件时出现致命错误 我正在处理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; } #包括 #包括 #包括 使用名称空间std; 内部主(空) { fstream指数; index.open(“file1”,ios::app); 索引,c++,file,file-handling,C++,File,File Handling,这通常意味着大括号没有关闭。在你的例子中,while循环没有用花括号关闭。我还认为你没有关闭if语句。这通常意味着大括号没有关闭。在你的例子中,while循环没有用花括号关闭。我还认为你没有关闭if语句。你错过了两个closin语句g大括号。我认为您的代码应该以以下行结尾: cout<<"the number of times the word occured in the file is "<<cnt<<endl; }

这通常意味着大括号没有关闭。在你的例子中,while循环没有用花括号关闭。我还认为你没有关闭if语句。

这通常意味着大括号没有关闭。在你的例子中,while循环没有用花括号关闭。我还认为你没有关闭if语句。

你错过了两个closin语句g大括号。我认为您的代码应该以以下行结尾:

            cout<<"the number of times the word occured in the file is "<<cnt<<endl;
        }
        index.close();
    }
    system("pause");
    return 0;
}

cout您遗漏了两个大括号。我认为您的代码应该以以下行结尾:

            cout<<"the number of times the word occured in the file is "<<cnt<<endl;
        }
        index.close();
    }
    system("pause");
    return 0;
}

cout您在cout之后会丢失一个'}',您在cout之后会丢失一个'}',您可以
t使用一个
fstream
实例读写文件。此处:
fstream索引;Indexy您可以
t通过一个
fstream
实例读取和写入文件。此处:
fstream索引;指数