Lab 06: File I/O in C++

This week's lab session will be based on Session 15 in the Lab Book, Files.  You'll find it helpful to read the introductory material in this section of the Lab Book and/or the material in a textbook on file I/O (such as pages 240-245 in A Computer Science Tapestry by Astrachan).


In the pages that follow, do any given exercises. Do all steps in each Experiment unless noted.

Remember, when the lab-book mentions a program, say, CP15E03, don't type it in! Copy it to your current directory:
cp ~cot3002l/src/CP15E03.cpp .
This means the C++ files are in the subdirectory named 'src' in the directory of the user-name 'course'. Don't forget the final '.' after the name of the C++ file. (This means the target of the copy command is the current directory, and just use the same name as in the source directory.)


Notes before starting:

Be sure you read the text descriptions of topics before each experiment. You may know most of this already, but there may be something in there you're not clear on! Remember it's not enough to do these exercises and forget the topics or skills, because you'll be expected to understand and use these concepts in later classes!

Important information on strings: You will be asked to do some things with C++ string objects in this lab. A lab on strings was done earlier in the term, so you should not have any problem if you remember what you learned then. (If not, review that.)


The Exercises To Do (Arranged by Topic)

The topics and exercises in this lab are grouped as follows. Click on the link below and you'll find comments and instructions about which exercises to do.

In this lab we'll also look at command-line arguments in C and C++.

Remember the command to compile your program is:
g++ -Wall prog_name.cpp
Always use the -Wall option with gcc to show all warnings, some of which might be errors. You could also use the -o option to rename the output file to be something other than a.out


Last modified on 06/26/2005.