Question
This program numbers the lines found in a text file. Write a C++ program that reads text from a file and outputs each line to
This program numbers the lines found in a text file. Write a C++ program that reads text from a file and outputs each line to the screen preceded by a line number. Print the line number at the start of the line and right-adjusted in a field of three spaces. Follow the line number with a colon, then one space, then the text of the line. You should get a character at a timeso you will not modify the content. You may assume that the lines are short enough to fit within a line on the screen.
Sample input file:
With three or four loggerheads amongst three or fourscore hogsheads. I have sounded the verybase-string of humility.Sirrah, I am sworn brotherto a leash of drawers; and can call them all bytheir christen names, as Tom, Dick, and Francis.They take it already upon their salvation, thatthough I be but the prince of Wales, yet I am kingofcourtesy; and tell me flatly I am no proud Jack,like Falstaff, but a Corinthian, a lad of mettle, agood boy, by the Lord, so they call me, and when Iam king of England, I shall command all the goodlads in Eastcheap.
Sample screen output:
1: With three or four loggerheads amongst three or four
2: score hogsheads. I have sounded the very
3: base-string of humility.Sirrah, I am sworn brother
4: to a leash of drawers; and can call them all by
5: their christen names, as Tom, Dick, and Francis.
6: They take it already upon their salvation, that
7: though I be butthe prince of Wales, yet I am king
8: ofcourtesy; and tell me flatly I am no proud Jack,
9: like Falstaff, but a Corinthian, a lad of mettle, a
10: good boy, by the Lord, so they call me, and when I
11: am king of England, I shall command all the good
12: lads in Eastcheap.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started