Code:
while (fin_A.get(ch) || fin_B.get(ch))
{
fin_A.getline(buf_A, 80); //read a line from the first file
fin_B.getline(buf_B, 80); //read a line from the second file
fout_C << buf_A << " " << buf_B << "\n"; //write the lines to the 3rd file
cout << "buf_A is: " << buf_A << "\n"; //show the value of buf_A on the screen
cout << "buf_B is: " << buf_B << "\n"; //show the values of buf_B on the screen
}
You've afforded us a good opportunity to see why C/C++ will "eat your lunch" if you don't understand what is taking place, waldis.
What does your WHILE test do? It reads a character from the first file - presumably to see if there is a line to be read - and, if not, tests the second file the same way.
The problem? (You see this coming, don't you? ) 'get()' consumes your first char. That's why all of the first characters from the first lines of your first file are missing.
Why only the first file? Logical OR ( || ) needs only one of the two conditions to be "true" in order for the loop execution to continue. If the first meets that criteria, the second is never tested.
Try this instead:
Code:
while ( fin_A || fin_B ){
// code
}
This syntax tests the error bits (flags) including EOF which is set only after the last char in the file is read. I'm betting this will clear up your problem.
-Skipper