Lecture Notes for Introduction to Computer Science II
12 July 2001 - Files in C++
- files store data
- external to the program - remains between program execution
- potentially long-lived data - but temp files
- potentially huge amounts of data - but lock files
- sharing data between programs
- file i-o moves data between files and programs
- often difficult to understand and use
- no one entity completely responsible - os, programming language
- unclear, under-specified, and ad hoc i-o models
- efficient i-o requires arcane knwoledge about obscure devices
- everybody implements their own - compatibility problem
- but getting better
- languages are providing standard i-o packages - learn once use
everywhere (ha!)
- clear and simple (sorta) i-o models
- but, still compatibility problems - file names, end of file
- the c++ file model
- a file is a sequence of zero or more bytes
- bytes are numbered like an array - from 0 (the start of the file) to
n (the end of the file); the file has size n + 1
- unlike an array, the size of a file can change
- a file has a name, which is how programs connect to files
- naming conventions are not standard -
a/b.cc
vs. a\b.cc
- a file has permissions, which may prevent various file i-o operations
- read-only files
- also operating system dependent
- won't affect your files, but other people's files.
This page last modified on 12 July 2001.