back
Reading Numberic Files
Now that you've learned how to write to a file, we can take a look at how to read a file. First, we will work with numerical files.

Check out this sample:

[numread.txt]

note: this is taken from page 214 of your book.

Compile and execute the program. Note that when you are using ios::in, the compiler assumes the data file is already there. If it is not there, you will get gibberish. If this occurs, you can copy the existing data file from your last project, or you can create a simple text file, save it and open it instead. If you choose the later, change your data file to a "txt" extension instead of "dat."

Reading String Data
Here is an example (from page 215) of how you read a file that has strings. Again, when you execute this file, you may have to copy the data file into the folder.

[stringread.txt]

Assignment

Create a text file with ten dates. Then write a program that will open that text file and display the dates.