fstream - Member Functions and Data by Group

Constructors & Destructor

Objects of the fstream class can be constructed and destructed.

~fstream
public:~fstream()

This is supported on AIX OS/400 z/OS

Destructs an fstream object.

fstream

Constructs an object of this class.

Overload 1
public:fstream(int fd, char* p, int l)

This is supported on AIX OS/400 z/OS

Constructs an fstream object that is attached to the file descriptor fd. If fd is not open, ios::failbit is set in the format state of the fstream object. This constructor also sets up an associated filebuf object with a stream buffer that has length l bytes and begins at the position pointed to by p. If p is equal to 0 or l is equal to 0, the associated filebuf object is unbuffered.

AIX and z/OS Considerations

This function is available for 32-bit applications. The third argument is an int value.

Overload 2
public:fstream(const char* name, int mode, _CCSID_T ccsid)

This is supported on OS/400

Constructs an fstream object and opens the file name with open mode equal to mode and ccsid equal to ccsid.

If the file cannot be opened, the error state of the constructed fstream object is set.

If the ccsid parameter is non-zero then it is treated as a CCSID (coded character set identifier) and will correspond to the CCSID of data written to and from the file. If the parameter value is zero then the CCSID of the job will be used.

Overload 3
public:fstream(int fd)

This is supported on AIX OS/400 z/OS

Constructs an fstream object that is attached to the file descriptor fd. If fd is not open, ios::failbit is set in the format state of the fstream object.

Overload 4
public:fstream(int fd, char* p, long l)

This is supported on AIX z/OS

Constructs an fstream object that is attached to the file descriptor fd. If fd is not open, ios::failbit is set in the format state of the fstream object. This constructor also sets up an associated filebuf object with a stream buffer that has length l bytes and begins at the position pointed to by p. If p is equal to 0 or l is equal to 0, the associated filebuf object is unbuffered.

This function is available for 64-bit applications. The third argument is a long value.

Overload 5
public:fstream( const char* name,
         int mode,
         int prot = filebuf::openprot,
         _CCSID_T ccsid = _CCSID_T ( 0 ) )

This is supported on OS/400

Constructs an fstream object and opens the file name with open mode equal to mode and protection mode equal to prot, and ccsid equal to ccsid.

The default value for the argument prot is filebuf::openprot. If the file cannot be opened, the error state of the constructed fstream object is set.

If the ccsid parameter is non-zero then it is treated as a CCSID (coded character set identifier) and will correspond to the CCSID of data written to and from the file. If the parameter value is zero then the CCSID of the job will be used.

Overload 6
public:fstream( const char* name,
         const char* attr,
         int mode,
         int prot = filebuf::openprot )

This is supported on z/OS

Constructs an fstream object and opens the file name with open mode equal to mode, attributes equal to attr and protection mode equal to prot.

The default value for the argument prot is filebuf::openprot. If the file cannot be opened, the error state of the constructed fstream object is set.

You can use the attr parameter to specify additional file attributes such as lrecl or recfm. All the parameters documented for the fopen() functions are supported, with the exception of type=record.

z/OS Considerations

The prot attribute is ignored.

Overload 7
public:fstream( const char* name,
         int mode,
         int prot = filebuf::openprot )

This is supported on AIX z/OS

Constructs an fstream object and opens the file name with open mode equal to mode and protection mode equal to prot.

The default value for the argument prot is filebuf::openprot. If the file cannot be opened, the error state of the constructed fstream object is set.

z/OS Considerations

The prot attribute is ignored.

Overload 8
public:fstream()

This is supported on AIX OS/400 z/OS

Constructs an unopened fstream object.

Filebuf Functions

Use these functions to work with the underlying filebuf object.

rdbuf
public:filebuf* rdbuf()

This is supported on AIX OS/400 z/OS

Returns a pointer to the filebuf object that is attached to the fstream object.

Open Functions

Opens the file.

z/OS Considerations

The prot parameter is ignored.

open

Opens the specified file.

Overload 1
public:void
  open( const char* name,
        int mode,
        int prot = filebuf::openprot )

This is supported on AIX z/OS

Opens the file with the name and attaches it to the fstream object. If the file with the name, name does not already exist, open() tries to create it with protection mode equal to prot, unless ios::nocreate is set.

The default value for prot is filebuf::openprot. If the fstream object is already attached to a file of if the call to fstream.rdbuf()->open() fails, ios::failbit is set in the error state for the fstream object.

The members of the ios::open_mode enumeration are bits that can be ORed together. The value of mode is the result of such an OR operation. This result is an int value, and for this reason, mode has type int rather than open_mode.

Overload 2
public:void
  open( const char* name,
        int mode,
        int prot = filebuf::openprot,
        _CCSID_T ccsid = _CCSID_T ( 0 ) )

This is supported on OS/400

Opens the file with the specified name, mode, protection and coded character set id and attaches it to the fstream object.

If the file with the name, name does not already exist, open() tries to create it with protection mode equal to prot, unless ios::nocreate is set.

The default value for prot is filebuf::openprot. If the fstream object is already attached to a file or if the call to fstream.rdbuf()->open() fails, ios::failbit is set in the error state for the fstream object.

The members of the ios::open_mode enumeration are bits that can be ORed together. The value of mode is the result of such an OR operation. This result is an int value, and for this reason, mode has type int rather than open_mode.

If the ccsid parameter is non-zero then it is treated as a CCSID (coded character set identifier) and will correspond to the CCSID of data written to and from the file. If the parameter value is zero then the CCSID of the job will be used.

Overload 3
public:void
  open( const char* name,
        const char* attr,
        int mode,
        int prot = filebuf::openprot )

This is supported on z/OS

Opens the file with the name and attaches it to the fstream object. If the file with the name, name does not already exist, open() tries to create it with protection mode equal to prot, unless ios::nocreate is set.

You can use the attr parameter to specify additional file attributes, such as lrecl or recfm. All the parameters documented for the fopen() function are supported, with the exception of type=record.

The members of the ios::open_mode enumeration are bits that can be ORed together. The value of mode is the result of such an OR operation. This result is an int value, and for this reason, mode has type int rather than open_mode.

Overload 4
public:void open(const char* name, int mode, _CCSID_T ccsid)

This is supported on OS/400

Opens the file with the specified name, mode and coded character set id and attaches it to the fstream object.

If the file with the name, name does not already exist, open() tries to create it unless ios::nocreate is set.

The members of the ios::open_mode enumeration are bits that can be ORed together. The value of mode is the result of such an OR operation. This result is an int value, and for this reason, mode has type int rather than open_mode.

If the ccsid parameter is non-zero then it is treated as a CCSID (coded character set identifier) and will correspond to the CCSID of data written to and from the file. If the parameter value is zero then the CCSID of the job will be used.