对于循环不读取ifstream

我正在尝试读取一个文件夹中的多个文件,以便可以解析它们的数据。 我首先尝试使用带有所有文件名的文本文档来填充列表,然后基于该字符串矢量,连续调用ifstream以便读取每个文件并处理单词数据。

The problem I'm running into is that ifstream is failing to open all of the files, except one in the middle of the list?
Heres the output, its failing to read the dbfiles but they all have the right names?

这些文件的大小不超过8GB,因此应该可以处理,但不是吗? 也许文件路径有问题?

 std::ifstream dbfiles(argv[1]);
    if (!dbfiles)
    {
        std::cerr << "Failed to open database " << argv[1] << " for reading." << std::endl;
    }


    std::string word;
    std::vector<std::string> dbfile_names;
    std::string file_name;

    while (getline(dbfiles, file_name))
    { //reading in the file names
        dbfile_names.push_back(file_name);
    }//populate list of dbs

    dbfiles.close();

    for (unsigned int j = 0; j < dbfile_names.size(); j++)
    { //for every single file

    std::ifstream dbfile(dbfile_names[j].c_str());
    if (!dbfile)
    {
        std::cout << "Failed to open database file" <<  dbfile_names[j] << " for reading. READ FAILURE" << std::endl;
    }else{
        std::cout << "currently reading " << dbfile_names[j] << std::endl;
    }

        while (dbfile >> word)
        { 
           //do stuff with the segments of data
           //here I gather the data word by word and process it
        }
        dbfile.close();
   }
评论