Reference for file
I/O
Laboratory 3: Command Line Arguments and File Parsing
In this lab, you
will learn how to get arguments from the command line.
You will also learn how to parse a
file (i.e. read and process the contents of a file).
- Topics to be explained by
your TA.
YOUR TASK
- Download ParseArguments.cpp
and try it with different command line arguments.
- Example: prog_name -o file1.txt -i
file2.txt
Program for parsing an
input file:
- Create a C++ program “fileparser” that reads through a file, and
outputs the parts between parentheses ‘(‘
and ‘)’.
- Your program should use command
line arguments to get the name of the input file.
- The program will be executed
at DOS prompt as
fileparser.exe <input_file>
- Create a project called “fileparser” containing the following files:
- “lab3.cpp” : The main program ( complete this by
adding your code )
- “parser.h” : This defines the class Parser (
download this file )
- “parser.cpp”
: The cpp file for the Parser ( write this on
your own )
- The program should do the following:
- Get the name of the input-file
from the command line.
- Open and read the file,
printing only the strings between ‘(‘ and
‘)’.
- Use the getstr()
method to read each such string and the printstr() method
to output the string.
- Implement the methods getstr() and printstr() of
the class “Parser”
- Use the following input files
to test your code:
SOLUTION
Lab3Sol.zip