.\" ident @(#)basic_ofstream.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH basic_ofstream 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2basic_ofstream\fP, \f2ofstream\fP, \f2wofstream\fP \ - Supports writing into named files or other devices associated with a file descriptor. .SH SYNOPSIS .br #include .br template > .br class basic_ofstream .br : public basic_ostream .SH DESCRIPTION The template class basic_ofstream supports writing into named files or other devices associated with a file descriptor. It uses a \f2basic_filebuf\fP object to control the associated sequences. It inherits from basic_ostream and can therefore use all the formatted and unformatted output functions. .SH INTERFACE .br template > .br class basic_ofstream .br : public basic_ostream { .br .br public: .br .RE .RS 1 typedef charT char_type; .br typedef traits traits_type; .br typedef typename traits::int_type int_type; .br typedef typename traits::pos_type pos_type; .br typedef typename traits::off_type off_type; .RE .RS 0 .RE .RS 1 typedef basic_ios ios_type; .RE .RS 0 .RE .RS 1 basic_ofstream(); .br explicit basic_ofstream(const char *s, .RE .RS 25 ios_base::openmode mode = .br ios_base::out, .br long protection = 0666); .RE .RS 0 .RE .RS 1 explicit basic_ofstream(int fd); .br basic_ofstream(int fd, char_type* buf, int len); .RE .RS 0 .RE .RS 1 virtual ~basic_ofstream(); .RE .RS 0 .RE .RS 1 basic_filebuf *rdbuf() const; .RE .RS 0 .RE .RS 1 bool is_open(); .br void open(const char *s, ios_base::openmode mode = .RE .RS 11 ios_type::out, long protection = 0666); .RE .RS 0 .RE .RS 1 void close(); .RE .RS 0 .br }; .SH TYPES .br char_type .RE .RS 3 The type \f2char_type\fP is a synonym for the template parameter \f2charT\fP. .RE .br off_type .RE .RS 3 The type \f2off_type\fP is a synonym of type \f2traits::off_type\fP. .RE .br ofstream .RE .RS 3 The type \f2ofstream\fP is an instantiation of class \f2basic_ofstream\fP on type \f2char\fP: \f2typedef basic_ofstream ofstream;\fP .RE .br int_type .RE .RS 3 The type\f2 int_type\fP is a synonym of type \f2traits::in_type\fP. .RE .br ios_type .RE .RS 3 The type \f2ios_type\fP is an instantiation of class \f2basic_ios\fP on type \f2charT\fP. .RE .br pos_type .RE .RS 3 The type \f2pos_type\fP is a synonym of type \f2traits::pos_type\fP. .RE .br traits_type .RE .RS 3 The type \f2traits_type\fP is a synonym for the template parameter \f2traits\fP. .RE .br wofstream .RE .RS 3 The type \f2wofstream\fP is an instantiation of class \f2basic_ofstream\fP on type \f2wchar_t\fP: \f2typedef basic_ofstream wofstream;\fP .RE .SH CONSTRUCTORS .br basic_ofstream(); .RE .RS 3 Constructs an object of class basic_ofstream, initializing the base class basic_ostream with the associated file buffer, which is initialized by calling the \f2basic_filebuf\fP constructor \f2basic_filebuf()\fP. After construction a file can be attached to the basic_ofstream_object using the \f2open\fP member function. .RE .br basic_ofstream(const char* s, .RE .RS 14 ios_base::openmode mode= ios_base::in, .br long protection= 0666); .RE .RS 3 Constructs an object of class basic_ofstream, initializing the base class basic_ostream with the associated file buffer, which is initialized by calling the \f2basic_filebuf\fP constructor \f2basic_filebuf()\fP. The constructor then calls the open function \f2open(s,mode,protection)\fP in order to attach the file whose name is pointed to by \f2s\fP, to the basic_ofstream object. The third argument, \f2protection\fP, is used as the file permissions. It does not appear in the Standard C++ description and is included as an extension. It determines the file read/write/execute permissions under UNIX. It is more limited under DOS since files are always readable and do not have special execute permission. .RE .RE .RS 0 explicit basic_ofstream(int fd); .RE .RS 3 Constructs an object of class basic_ofstream, initializing the base class basic_ostream with the associated file buffer, which is initialized by calling the \f2basic_filebuf\fP constructor \f2basic_filebuf()\fP. The constructor then calls the \f2basic_filebuf\fP open function \f2open(fd)\fP in order to attach the file descriptor \f2fd\fP to the basic_ofstream object. This constructor is not described in the C++ standard, and is included as an extension in order to manipulate pipes, sockets, or other UNIX devices that can be accessed through file descriptors. If the function fails, it sets \f2ios_base::failbit.\fP .RE .br basic_ofstream(int fd, char_type* buf,int len); .RE .RS 3 Constructs an object of class basic_ofstream, initializing the base class basic_ostream with the associated file buffer, which is initialized by calling the \f2basic_filebuf\fP constructor \f2basic_filebuf()\fP. The constructor then calls the \f2basic_filebuf\fP open function \f2open(fd)\fP in order to attach the file descriptor \f2fd\fP to the basic_ofstream object. The underlying buffer is then replaced by calling the \f2basic_filebuf\fP member function \f2setbuf\fP with parameters \f2buf\fP and \f2len\fP. This constructor is not described in the C++ standard, and is included as an extension in order to manipulate pipes, sockets, or other UNIX devices that can be accessed through file descriptors. It also maintains compatibility with the old iostreams library. If the function fails, it sets \f2ios_base::failbit.\fP .RE .SH DESTRUCTORS .br virtual ~basic_ofstream(); .RE .RS 3 Destroys an object of class \f2basic_ofstream\fP. .RE .SH MEMBER FUNCTIONS .br void .br close(); .RE .RS 3 Calls the associated \f2basic_filebuf\fP function \f2close()\fP and if this function fails, it calls the \f2basic_ios\fP member function \f2setstate(failbit)\fP. .RE .br bool .br is_open(); .RE .RS 3 Calls the associated \f2basic_filebuf\fP function \f2is_open()\fP and returns its result. .RE .br void .br open(const char* s,ios_base::openmode = .RE .RS 9 ios_base::out, long protection = 0666); .RE .RS 3 Calls the associated \f2basic_filebuf\fP function \f2open(s,mode,protection)\fP and, if this function fails opening the file, calls the \f2basic_ios\fP member function \f2setstate(failbit)\fP. The third argument, \f2protection\fP, is used as the file permissions. It does not appear in the Standard C++ description and is included as an extension. It determines the file read/write/execute permissions under UNIX, and is more limited under DOS since files are always readable and do not have special execute permission. .RE .RE .RS 0 basic_filebuf* .br rdbuf() const; .RE .RS 3 Returns a pointer to the \f2basic_filebuf \fPassociated with the stream. .RE .SH EXAMPLE See basic_fstream, basic_ifstream and basic_filebuf examples. .SH SEE ALSO char_traits(3C++),_ios_base(3C++), basic_ios(3C++), basic_filebuf(3C++), basic_ifstream(3C++), basic_fstream(3C++) Working Paper for Draft Proposed International Standard for Information Systems--Programming Language C++, Section 27.8.1.8 .SH STANDARDS CONFORMANCE ANSI X3J16/ISO WG21 Joint C++ Committee