How would I subtract two text files from each other, and the output gets stored into another text file?
As you can see in my code, lets say averageRainfall.txt stores 1,2,3,4,5
while rainfallToDate.txt has 7,3,5,7,4. How would I write the code to have averageRainfall.txt subtract rainfallToDate.txt and storing it in rainfall.txt?
Read from input files, perform the subtraction, and write to the output file. E.g.:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <fstream>
int main() {
std::ifstream inA("averageRainfall.txt");
std::ifstream inB("rainfallToDate.txt");
std::ofstream out("rainfall.txt");
int a;
int b;
while (inA >> a && inB >> b) {
out << (a - b) << ",";
// ignore delimiters
inA.get();
inB.get();
}
return 0;
}