counting numbers from a file | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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; }

18th Jun 2019, 6:49 AM
Deepak Chekuri
1 Answer
+ 1
Thanks, it worked.
18th Jun 2019, 7:10 AM
Deepak Chekuri