Question: Code prompt: Write a C + + program that reads lines from a file until the end of file. The program should prompt the user

Code prompt: Write a C++ program that reads lines from a file until the end of file. The program should prompt the user for the file name to read from. The program should open the file for reading, and if the file cannot be opened, it should print the message "File cannot be opened ", followed by the filename, and exit.
The program acts like a simple interpreter for a scripting/command language. The file includes commented lines that are recognized by either the character #, as the start character of the line; or by //, as the first two characters of the line. The program should skip over all commented lines. For the rest of the file, the program should keep track of the total number of lines read, the number of non-commented lines, the line of the maximum length, the number of words, and the word of maximum length.
A word is defined as a sequence of one or more non-whitespace characters. Note that a line having only whitespace characters is referred to as a blank line. After reading the contents of the input file, the program should print out the total number of lines, the number of non-commented lines, the line of the maximum length delimited by double quotes, the number of words, and the word of maximum length delimited by double quotes, as shown in the following example.
How would i code this with get() or getlin(), and length()
Also use istringstream for each readline to extract each word in line into stringthe generated results after reading the file contents are as follows:
Enter the name of a file to read from:
infile 6
Total Number of Lines: 11
Number of non-commented lines: 9
Line of Maximum Length: "67899 smith 9643.45"
Number of words: 10
Word of Maximum Length: "9643.45"
 Code prompt: Write a C++ program that reads lines from a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!