appending data from text files

Hi everyone,
I'm working with two txt files. If they contain the same number of lines then my code will output and append the data to another text file successfully. However, if one file contains an extra line of data, that line doesn't get captured into the output file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void readWriteFiles(ifstream& fin1, ifstream& fin2, ofstream& fout, string& filename1, string& filename2, string& fileOut)
{
	string fileOneContent, fileTwoContent;
	int amtOfLine1 = 0;
	int amtOfLine2 = 0;		
	while (getline(fin1, fileOneContent, '\n') && getline(fin2, fileTwoContent, '\n'))
		{
			amtOfLine1++;
			amtOfLine2++;
			cout << endl;
			cout << "Reading line " << amtOfLine1 << " from " << filename1 << "\n";
			cout << "Reading line " << amtOfLine2 << " from " << filename2 << "\n";
			cout << "Writing line " << amtOfLine1 << " to " << fileOut << "\n";
			fout << fileOneContent << " " << fileTwoContent << "\n";
		}
return;
}


Do I need to add some other logic to this code? Thanks in advance.
change && with || and add this at the end of your function
1
2
fileOneContent = "";
fileTwoContent = "";


note: this is not a good solution
yea that captures all the lines in both files but in the output file I need to be able to append line 1 from the second input file to line 1 of the first input file, and so on...
Topic archived. No new replies allowed.