I got this program to finnally compile but cant seem to get it to read a single bit of data from the file. I have a input.txt file in the same directory. It crashes as soon as i put in the file name.
Please assist. I am pulling my hair out on this one. Thanks in advance for your help.
Code:#include <iostream> #include <fstream> #include <string> #include <cassert> using namespace std; int main() { string fileName; cout << "Enter name of file: "; getline(cin, fileName); ifstream inFile(fileName.data()); assert(inFile.is_open()); while (!inFile.eof()) { int ch; int i=0; int line; int totalChars; int minChars; int maxChars; int minLine; int maxLine; i++; /* Count the characters*/ if ( ch=='\n') { line++; /* increment when a newline is found*/ totalChars += i-1; /* Correction for \n (newline) character*/ } if (i<minChars) { minChars = i; minLine = line; } else if (i>maxChars || minChars>maxChars) { maxChars = i; maxLine = line; } i = 0; cout << "The input file has " << line << "\n"; cout << "The average number of characters per line is " << totalChars << "\n"; cout << "The line that is the shortest and its characters is " << minLine << " " << minChars << "\n"; cout << "The line that is the longest and its characters is " << maxLine << " " << maxChars << "\n"; return 0; } }