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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -