Question: Write a head program in head.cpp . The head program should read the first n lines of either a file or standard input If n
Write a head program in head.cpp
The head program should read the first n lines of either a file or standard input
If n isn't provided, print lines
If no file is provided, read the lines from standard input cin
There are four possible scenarios for commandline arguments:
No arguments: the program should read lines from standard input.
argument that is an input file: the program should attempt to read lines from the file.
argument that is a number of lines n: the program should read that number of lines from standard input.
NOTE: Empty lines count as valid input. The program should accept them the same way it accepts nonempty lines.
arguments: the program should read n lines from the file.
If the input file does not exist, the program should print an error message and exit
If more lines are requested than the input file has, the program should just print as many lines as the file has and no extras.
Follow the formatting demonstrated in the example
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
