i am trying to find sum in a file and output it to another , however when i open the output file the sum is still 0?
include <fstream>
using namespace std;
void main() {
ifstream fin("inFile.txt"); // create input stream & connects to file
ofstream fout("outFile.txt"); // create output stream & connects to file
int n = 0, sum = 0, num = 0;
fin >> n; // read the number of integers from inFile.txt
for (int i = 0; i < n; i++) {
fin >> num;
sum = sum + num;
}
fout << "sum is " << sum << endl;
fin.close();
fout.close();
}