I am trying to read a file so that I can average out the numbers listed in the file. I believe my code is correct, but I keep getting an error in Visual Studio stating, "Unable to start program ... The system cannot find the file specified." The file I want to read, "numbers.dat" is in the directory, but it still shows this error.
I'm new to C++ so I was wondering if anyone would be able to help?
Here is my code
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream myfile;
myfile.open("numbers.dat");
int total = 0, count = 0, num;
while (!myfile.eof()){
myfile>>num;
total += num;
count++;
}
cout<<"The "<<count<<" numbers total "<<total<<" and average "<<total/count<<endl;
myfile.close();
system("pause");
return 0;
}