C/C++ Standard File API

Contents

C Interface
C++
Both C and C++ define high-level interfaces to file manipulation, independent of any particular O/S. Code written using these interfaces is usually portable to any O/S.

C Interface

C defines an opaque data structure of type FILE that you never need to look into. Functions that use this include
# include <stdio.h>

FILE *fopen(char *path, char *type);
int remove(char *path);
int fclose(FILE *fp);
Once a file has been opened there are a variety of functions to read/write such as
#include <stdio.h>

fprintf(FILE *fp, char *format, ...);
int fputc(char c, FILE*fp);
int fgetc(FILE *fp);

C++

All the C functions for I/O are available in C++. In addition, C++ has the iostream classes with their associated methods. These allow you to create, open, close, rad and write files.
Home Program Development using Unix Home
Jan Newmarch (http://jan.newmarch.name)
jan@newmarch.name
Last modified: Wed Nov 19 17:56:49 EST 1997
Copyright ©Jan Newmarch