Slides_External_Files

Slides_External_Files - Today in CS162 External Files What...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
CS162 External Data Files 1 Today in CS162 External Files What is an external file? How do we save data in a file?
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS162 External Data Files 2 External Files So far, all of our programs have used main memory to temporarily store information. In addition, all input and output has been done with standard-in and standard-out devices this includes input from the keyboard and output to our terminal's screen for prompts, echoing data, and displaying results Now it is time to work with secondary storage!
Background image of page 2
CS162 External Data Files 3 External Files Typically, secondary storage consists of a hard disk. ...however, some of you may end up using a floppy as your secondary storage. With ODIN, we will be using a hard disk. Those of you using PCs, will use a combination of hard disks and floppies.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS162 External Data Files 4 External Files There is one big difference between main memory and secondary storage. Remember with main memory, each time we run our program the value of our variables is lost and we start from scratch (i.e., we don't remember what the values of the variables were when we last ran the program). Also, when we power down the computer all of the data stored in main memory goes away.
Background image of page 4
CS162 External Data Files 5 External Files: Secondary Storage With files, when you finish executing a program, the data no longer goes away! It stays around so you can access it the next time you run your program. Plus, when your computer is powered down, information stored in secondary storage is not lost (unless you have a disk crash or failure!). Therefore, secondary storage can be used to store data for as long as it is needed.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS162 External Data Files 6 External Files: Secondary Storage We can write information to secondary storage by creating a file which consists of a collection of data. We then name this file, so that we can store different types of information all in one directory or on one disk. We will be using text files in this class (and in CS162)
Background image of page 6
CS162 External Data Files 7 External Files: Secondary Storage A text file contains the same kind of data that we are used to seeing on the screen of our terminals. What this means is that a text file is a stream of characters: line by line. Therefore, these are files of characters. Lines in our files can be separated by end- of-lines ('\n'). This defines how many characters there are on a line and how many lines there are in the text file.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS162 External Data Files 8 External Files: Secondary Storage To use a text file to store information, we first need to include a new library of I/O functions, declare input/output stream variables to be used instead of cin and cout, and attach a C++ input or output stream to that file.
Background image of page 8
CS162 External Data Files 9 External Files: Secondary Storage Text files all have names, called filenames. If you do a directory (ls on ODIN),
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 40

Slides_External_Files - Today in CS162 External Files What...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online