I'm trying to get the number of lines in a txt file. This is the method I've been trying to implement, but it prints n=1.
#include <iostream>
#include <string>
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(){
int n=0;
string line;
ifstream fdatos;
fdatos.open("temp_toma5.txt");
while (!fdatos.eof()){
getline(fdatos, line);
n++;
}
cout<<"n = "<<n<<endl<<endl;
fdatos.close();
return 0;
}
This is the structure of the file
0 0.03 0
5 0.03 0.01
10 0.02 0
15 0.02 0
20 0.02 0
25 0.03 0
30 0.03 0
Thank you in advanced