【问题标题】:Merging 3 files together, works fine when merging the same three files but when mergin 3 different files, it doesnt want to read the 3rd file将 3 个文件合并在一起,在合并相同的三个文件时工作正常,但在合并 3 个不同的文件时,它不想读取第三个文件
【发布时间】:2021-06-04 05:42:20
【问题描述】:

所以标题说明了一切,我试图将 3 个单词列表连接在一起,但由于某种原因它不想阅读第 3 个列表,

第一个词表单词:

减号

第二个词表单词:

也没有

否定

第三个词表单词:

异或

void merge3(string MFile3)
{

string file1name, file2name,file3name, outfilename, word1, word2, word3;
cout << "Enter name of first file: ";
cin >> file1name;
cout << "Enter name of second file: ";
cin >> file2name;
cout << "Enter name of third file: ";
cin >> file3name;
cout << "Enter name of output file: ";
cin >> outfilename;


ofstream inFileFour(outfilename.c_str());

ifstream inFileOne(file1name.c_str());
while (inFileOne >> word1) {
    ifstream inFileTwo(file2name.c_str());
    

    while (inFileTwo >> word2) {

        ifstream inFileThree(file2name.c_str());
    
        while (inFileThree >> word3) {
            

            inFileFour << word1 << word2 << word3 << endl;

        }
        inFileThree.close();
    }

    inFileTwo.close();
    
}
inFileOne.close();
inFileFour.close();

}

有错误的词表,前 2 个词表显示,但不显示第 3 个

包含所有可能组合的单词列表,期望与文件

如果有人可以让我知道这里发生了什么,那就太好了,我愿意接受建议。

【问题讨论】:

标签: c++ string-concatenation


【解决方案1】:

第三个文件永远不会被读取,你正在再次读取第二个文件:

ifstream inFileThree(file2name.c_str());

【讨论】:

  • WOOOOW,我很抱歉我的菜鸟错误,感谢您抽出宝贵时间查看它!
  • 没问题,每个人都会遇到。
猜你喜欢
  • 1970-01-01
  • 2016-10-13
  • 2012-02-14
  • 1970-01-01
  • 2017-12-23
  • 2012-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多