0

I have a text file containing a list of files seperated by line. I'm trying to open each file, and then process the data within each, however the ONLY file that successfully opens is the LAST file in the list. Any idea why this is happening?

input file looks like this:

Microsoft Office Professional Plus 2010.txt
Microsoft Office OneNote MUI (English) 2010.txt
Microsoft Office InfoPath MUI (English) 2010.txt
Microsoft Office 2010 Primary Interop Assemblies.txt
Microsoft Office Access MUI (English) 2010.txt

Source code:

void loadCVEDescription(char* CVEDescList) {
    vector<string> fileList;
    ifstream inputFile(CVEDescList);
    string descfile = "";

    while(!inputFile.eof()){
        getline(inputFile,descfile);
        descfile = "C:\\path\\path\\" + descfile;
        fileList.push_back(descfile);
    }
    inputFile.close();

    for(size_t t = 0; t < fileList.size(); t++){
        ifstream dataFile;
        string pname = descfile.substr(descfile.find_last_of("\\")+1,descfile.find(".txt"));
        int i = findProductIndex(pname);
/*
  findProductIndex(string pname) searches product[] and returns the index 
  at which products[i].productName matches pname
*/
         dataFile.open(fileList[t]);
         if(dataFile.is_open()){
             cout << fileList[t] << " success" << endl;
        }

        dataFile.close();
        dataFile.clear();

    }

}

The ONLY file which successfully opens is the LAST one in the input file.

  • 1
    You should read about why [`while (!file.eof())` is always wrong](http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong). – molbdnilo May 18 '16 at 16:56
  • I'm successfully reading the entire file into my vector ( I have checked this), so is this is not my issue, though it is something I will read more into as it seems more of just a c++ best practice. – user5904091 May 18 '16 at 17:01
  • have you try to check the badbit set by the open when it fails ? are you sure the path are correct ? – ponayz May 18 '16 at 17:13
  • The badbit for every single open returns 1, and yes im positive the paths are correct. – user5904091 May 18 '16 at 17:19

0 Answers0