重点:
每次打开新文件前,确保上一次的文件对象在close()之前被clear()!
// declare one ifstream object for every file
ifstream FileObject;
//open a input file which contain names of all files
ifstream InputFile("Input.txt");
while(std::getline(InputFile,buf)){
std::string name=buf;
FileObject.open(name.c_str());
if (!FileObject.is_open()){
//report error here.
continue;
}
while(std::getline(FileObject,buf2))
{ //doing some validation operations. }
//Clear the fileobject for next use
FileObject.clear();
//Prepare for next open,每次打开前都要clear和close
FileObject.close();
}
没有评论:
发表评论