I want to count number of lines in a file.But here I am getting the number of lines in file+1 as answer. For example, if my file has 2 lines then my code will give 3 as answer.
Here is my code-
int c=0;
void number()
{ 
   cout<<"NO. OF LINES :"<<c<<endl;
}
 
int main()
{
   string line;
   ifstream file("text1.txt");
   
   if(file.is_open())
   {
       while(!file.eof())
       {
           getline(file,line);
           cout<<line<< endl;
           c++;
        }
        file.close();
    }
    number();
}
 
     
    