// "Conflate" two sorted integer lists. #include #include using namespace std; int main() { ifstream listA, listB; // The two input files int numA, numB; // Values from the input // Open the first file. listA.open("a.dat"); if ( !listA ) { cerr << "Unable to open a.dat file\n"; return 1; } // Open the second file. listB.open("b.dat"); if ( !listB ) { cerr << "Unable to open b.dat file\n"; return 1; } // Conflate (or merge) numbers from the two input list files. listA >> numA; listB >> numB; while ( listA || listB ) { if ( !listB || ( listA && numA < numB ) ) { cout << numA << endl; listA >> numA; } else if ( !listA || numA > numB ) { cout << numB << endl; listB >> numB; } else // numA == numB { cout << numA << endl; listA >> numA; listB >> numB; } } // Close both input files. listA.close(); listB.close(); return 0; }