Task is - For given ordered numerical files f and g, write a program to merge these two files into an ordered file ff . But my while loop is don't work correctly and don't comletely understand how to read data from the files by the end
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream ff;
ifstream f, g;
const char* n1 = "f.txt", * n2 = "g.txt", * n3 = "ff.txt";
f.open(n1);
g.open(n2);
ff.open(n3);
if (!f.is_open() || !g.is_open()) {
cout << "File problems " << endl;
return 1;
}
char strf[5], strg[5];
int f_, g_;
f >> strf;
g >> strg;
f_ = atoi(strf);
g_ = atoi(strg);
while (!f.eof() && !g.eof()) {
while (f_ <= g_) {
if (f_ != g_) {
ff << f_;
}
f >> strf;
f_ = atoi(strf);
}
g >> strg;
g_ = atoi(strg);
ff << g_;
}
ff.close();
return 0;
}