In this unit, we will first explore the concept of generic programming, and how you can harness the power of templates to make classes and functions more reusable and adaptable to your personal needs. Then, we will explore ways to add content to our program by reading from files and then storing the data by writing to output files. Finally, we will explore the use of exceptions in C++. Exceptions allow us to anticipate problems that might occur in code and handle this problems through the use of exceptions, telling the program specifically how it is to behave when these problems occur.
Completing this unit should take you approximately 8 hours.
The ability to read from a file is a critical task that allows for batch processing. Watch this video to learn how you can read data from a file, so that data input doesn't always have to come from the keyboard.
Sometimes once you have finished processing your data, you want to save the data so that it can be re-input at a later time as an input file. Watch this video to learn how to write to an output file using output file streams.
Read this article and complete the exercises at the end to test your skills in inputting from and outputting to files.
When things go wrong in programming, as they usually do, the last thing you want is for the program to crash or perform some erroneous actions. Using exception handling allows the programmer to control what happens when the unexpected happens.
Complete these activities to practice reading from and writing to files.