0
counting numbers from a file
Hey guys, i'm writing a code to count total numbers in a file(contains only integers).This is my code and i'm unable to figure out the error. #include<iostream> #include<cstdlib> #include<fstream> using namespace std; int main() { int numbers; ifstream fin; ofstream fout; fin.open("numbers.dat"); if(fin.fail()) { cout<<"opening number file is failed\n"; exit(1); } int count=0; while(!fin.eof()) { count++; } cout<<count<<endl; fin.close(); return 0; }
1 Answer
+ 1
Thanks, it worked.