Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to count how many lines are in a text file. How do I makethe program reco

ID: 3616668 • Letter: I

Question

I need to count how many lines are in a text file. How do I makethe program recognize the EOLN?
This is what I have. Should I have the program read off eachcharacter and then when it reaches an EOLN have an if statementwith a counter in it?

#include <iostream>                  
#include <fstream>
#include <string>                  
using namespace std;

int main ()
{
    string fileName;
    ifstream inFile;
    int lineCount++;

    cout << "Enter a valid filename (noblanks!): ";
    cin >> fileName;
    inFile.open (fileName.c_str());  

     while (inFile)
     {
          lineCount++;
      }

Explanation / Answer

please rate - thanks #include                   #include #include                   using namespace std; int main () {     string fileName;     char input[81];     ifstream inFile;     int lineCount=0;     cout > fileName;     inFile.open (fileName.c_str());     inFile.getline(input,100);      while (inFile)      {           lineCount++;       inFile.getline(input,100);         } cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote