|
|
1.1 ! root 1: . \"ident "%W%" ! 2: . \"Copyright (c) 1984 AT&T ! 3: . \"All Rights Reserved ! 4: . \"THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T ! 5: . \"The copyright notice above does not evidence any ! 6: . \"actual or intended publication of such source code. ! 7: .TH FSTREAM 3I+ "C++ Stream Library" " " ! 8: .SH NAME ! 9: fstream \- iostream and streambuf specialized to files ! 10: .SH SYNOPSIS ! 11: .nf ! 12: .ft B ! 13: .ta1i 2i ! 14: #include <fstream.h> ! 15: ! 16: typedef long streamoff, streampos; ! 17: class ios { ! 18: public: ! 19: enum seek_dir { beg, cur, end }; ! 20: enum open_mode { in, out, ate, app } ; ! 21: // \fIand lots of other stuff ... \fP ! 22: } ; ! 23: ! 24: class ofstream : ostream { ! 25: ofstream() ; ! 26: ofstream(char* name, open_mode mode, int prot=0664) ; ! 27: ofstream(int fd) ; ! 28: ofstream(int fd, char* p, int l) ; ! 29: ! 30: void attach(int fd); ! 31: void close(); ! 32: void open(char* name, open_mode, int=0664) ; ! 33: filebuf* rdbuf(); ! 34: }; ! 35: ! 36: class ifstream : istream { \fI same as ofstream\fP }; ! 37: class fstream : iostream { \fI same as ofstream\fP }; ! 38: .fi ! 39: .ft R ! 40: .SH DESCRIPTION ! 41: \f(CWifstream\fRs, \f(CWofstream\fR and \f(CWfstream\fR ! 42: specialize \f(CWistream\fR, \f(CWostream\fR and \f(CWiostream\fR ! 43: (respectively) to files. ! 44: That is, the associated streambuf will be a \f(CWfilebuf\fR. ! 45: .PP ! 46: Assume ! 47: .br ! 48: \(em \fBf\fR any of \f(CWifstream\fR, \f(CWofstream\fR or \f(CWfstream\fR. ! 49: .br ! 50: \(em \fBpfb\fR is a \f(CWfilebuf*\fR. ! 51: .br ! 52: \(em \fBpsb\fR is a \f(CWstreambuf*\fR. ! 53: .br ! 54: \(em \fBname\fR and \fBptr\fR are \f(CWchar*\fR. ! 55: .br ! 56: \(em \fBi\fR, \fBfd\fR, \fBlen\fR and \fBprot\fR are \f(CWint\fR. ! 57: .br ! 58: \(em \fBmode\fR is an \f(CWopen_mode\fR. ! 59: .PP ! 60: The constructors for \fIx\f(CWstream\fR, where \fIx\fR is either ! 61: \f(CWif\fR, ! 62: \f(CWof\fR or \f(CWf\fR, are: ! 63: .TP ! 64: \fIx\fBstream()\fR ! 65: Constructs an unopened \f(CWxstream\fR. ! 66: .TP ! 67: \fIx\fBstream()(name,mode,prot)\fR ! 68: Constructs an \f(CWxstream\fR and tries to opens it using ! 69: \fBname\fR, \fBmode\fR, and \fBprot\fR. ! 70: The status of the constructed \f(CWxstream\fR ! 71: will indicate failure in case the ! 72: \fBopen\fR fails. ! 73: .TP ! 74: \fIx\fBstream()\fR ! 75: Constructs an \f(CWxstream\fR connected to file descriptor \fBd\fR, ! 76: which must be previously opened. ! 77: .TP ! 78: \fIx\fBstream(d,ptr,len)\fR ! 79: Constructs an \f(CWxstream\fR connected to file descriptor \fBfd\fR ! 80: and in addition initializes ! 81: the associated \f(CWfilebuf\fR to use the \fBlen\fR bytes ! 82: at \fBptr\fR as the ! 83: reserve area. If \fBptr\fR is null or \fBlen\fR is 0, the \f(CWfilebuf\fR ! 84: will be unbuffered. ! 85: .PP ! 86: Member functions: ! 87: .TP ! 88: \fBf.attach(d)\fR ! 89: Connects \fBf\fR to the file descriptor \fBd\fR. ! 90: A failure occurs when \fBf\fR is already connected to a file. ! 91: A failure sets \f(CWfailbit\fR in \fBf\fR's error state. ! 92: .TP ! 93: \fBf.close()\fR ! 94: Closes any associated \f(CWfilebuf\fR and thereby breaks the connection ! 95: of the \fBf\fR to a file. ! 96: \\fBf\fR's error state is cleared except on failure. ! 97: A failure occurs when the call to \fBf.rdbuf()->close\fR fails. ! 98: .TP ! 99: \fBf.open(name,mode,prot)\fR ! 100: Opens file \fBname\fR and connects \fBf\fR to it. ! 101: If the file is created, it is created with protection mode \fBprot\fR. ! 102: \fBopen\fR normally returns 0, but it returns \f(CWEOF\fR on failure. ! 103: Failure ! 104: occurs if \fBf\fR is already open, or the call to \fBf.rdbuf()->open\fR ! 105: fails. \f(CWfailbit\fR is set in \fBf\fR's error status on failure. ! 106: The members of \f(CWopen_mode\fR are bits that may be or'ed together. ! 107: The meaning of these bits in \fBmode\fR is ! 108: .RS ! 109: .TP ! 110: \f(CWapp\fR ! 111: A seek to the end of file is performed. ! 112: Subsequent data written to the file is always added (appended) ! 113: at the end of file. ! 114: On some systems this is implemented in the kernel. ! 115: In ! 116: others it is implemented by seeking to the end of the file ! 117: before each write. \f(CWapp\fR implies \f(CWoutput\fR. ! 118: .TP ! 119: \f(CWate\fR ! 120: A seek to the end of the file is performed during the \fBopen\fR. ! 121: \f(CWate\fR does not imply \f(CWoutput\fR. ! 122: .TP ! 123: \f(CWin\fR ! 124: Implied by construction and opens of \f(CWifstream\fRs. ! 125: For \f(CWfstream\fRs it indicates that input operations should be ! 126: allowed possible. Is is legal to include \f(CWin\fR in the modes ! 127: of an \f(CWostream\fR in which case it implies that the original ! 128: file (if it exists) should not be truncated. ! 129: .TP ! 130: \f(CWout\fR ! 131: Implied by construction and opens of \f(CWofstream\fRs. ! 132: For \f(CWfstream\fR it says that output operations are to ! 133: be allowed. ! 134: .RE ! 135: .TP ! 136: \fBpfb=f.rdbuf()\fR ! 137: Returns a pointer to the associated \f(CWfilebuf\fR. ! 138: \fBfstream::rdbuf\fR has the same meaning as ! 139: \fBiostream::rdbuf\fR ! 140: but is typed differently. ! 141: .TP ! 142: \fBpsb=f.setbuf(p,len)\fR ! 143: Has the usual effect of a \fBsetbuf\fR, offering space ! 144: for a reserve area or requesting unbuffered I/O. ! 145: Normally the returned \fBpsb\fR is \fBf.rdbuf()\fR, but it is 0 ! 146: on failure. ! 147: A failure occurs if \fBf\fR is open or the call to \fBf.rdbuf()->setbuf\fR ! 148: fails. ! 149: .SH SEE ALSO ! 150: filebuf(3C++) ! 151: istream(3C++) ! 152: ios(3C++) ! 153: ostream(3C++) ! 154: sbuf.pub(3C++)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.