c++ - Failing to read values from a file -
the program below should read in bunch of integers file , work out average:
#include "stdafx.h" #include <iostream> #include <string> #include <fstream> using namespace std; int main( int argc, char** argv ) { ifstream fin( "mydata.txt" ); int i, value, sum = 0; ( = 0; fin >> value; i++ ) { sum += value; } if ( > 0 ) { ofstream fout( "average.txt" ); fout << "average: " << ( sum / ) << endl; } else { cerr << "no list average!" << endl; } system( "pause" ); }
the file mydata.txt
exists in same directory , contains 1 2 3 4 5
output always: no list average!
what doing wrong skips calculation , output file generation parts?
thanks help,
h
i guess mydata.txt not in same directory executable, code works me
Comments
Post a Comment