Lecture Notes for Introduction to Computer Science II

12 July 2001 - Files in C++


  1. files store data

    1. external to the program - remains between program execution

    2. potentially long-lived data - but temp files

    3. potentially huge amounts of data - but lock files

    4. sharing data between programs

  2. file i-o moves data between files and programs

    1. often difficult to understand and use

      1. no one entity completely responsible - os, programming language

      2. unclear, under-specified, and ad hoc i-o models

      3. efficient i-o requires arcane knwoledge about obscure devices

      4. everybody implements their own - compatibility problem

    2. but getting better

      1. languages are providing standard i-o packages - learn once use everywhere (ha!)

      2. clear and simple (sorta) i-o models

      3. but, still compatibility problems - file names, end of file

  3. the c++ file model

    1. a file is a sequence of zero or more bytes

    2. 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

    3. unlike an array, the size of a file can change

    4. a file has a name, which is how programs connect to files

      1. naming conventions are not standard - a/b.cc vs. a\b.cc

    5. a file has permissions, which may prevent various file i-o operations

      1. read-only files

      2. also operating system dependent

      3. won't affect your files, but other people's files.


This page last modified on 12 July 2001.