0

So title says it all, im trying to concatenate 3 wordlists together however for some reason it does not want to read the 3rd list,

first wordlist words:

nand

minus

second wordlist words:

nor

negative

third wordlist words:

xor

plus

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();

}

the wordlist with the errors, the first 2 word lists show but not 3rd one

the wordlist with all possible combinations expect with file

1

If anyone can let me know what is going on here that would be great, im open to suggestions.

Sudo-su-cm
  • 23
  • 1
  • 9
  • See [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/), consider a chat with the duck, and see [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/q/25385173/3422102). Being able to step through your code and diagnose the errors is every bit as important as being able to write and compile the code. – David C. Rankin Jun 04 '21 at 06:21

1 Answers1

2

The third file is never read, you are reading the second file again:

ifstream inFileThree(file2name.c_str());
Ella Blackledge
  • 329
  • 1
  • 7