United States    
COMPAQ
C++
Compaq C++

Compaq C++
Class Library Reference Manual


Previous Contents Index


OAPP(TYPE) class

For an ostream object, declares predefined parameterized applicators.

Header File

#include <iomanip.hxx>

Alternative Header

#include <iomanip.h>


Compile-Time Parameter

TYPE---The type of the ostream object. It must be an identifier.

Declaration


class OAPP(TYPE) 
{ 
public: 
    OAPP(TYPE)(ostream &(*f)(ostream &, TYPE)); 
    OMANIP(TYPE) operator()(TYPE a); 
}; 


Constructor

OAPP(TYPE)(ostream &(*f)(ostream &, TYPE))

Creates an applicator.

Operator

OMANIP(TYPE) operator () (TYPE a)

Casts an object of type a into a manipulator function for an ostream object.

See Also

OMANIP(TYPE) class

ofstream class

Supports output to files.

Header File

#include <fstream.hxx>

Alternative Header

#include <fstream.h>


Declaration


class ofstream: public ostream 
{ 
public: 
                 ofstream(); 
                 ofstream(const char *name, int mode = ios::out, 
                         int prot = filebuf::openprot); 
                 ofstream(int fd); 
                 ofstream(int fd, char *p, int len); 
                 ~ofstream(); 
 
    void         attach(int fd); 
    void         close(); 
    void         open(const char *name, int mode = ios::out, 
                         int prot = filebuf::openprot); 
    filebuf      *rdbuf(); 
    void         setbuf(char *p, int len); 
}; 


Description

This class specializes the ostream class to files using a filebuf object to do the output. Your program can perform common operations, such as opening and closing files, without explicitly mentioning filebuf objects.


Constructors and Destructors

ofstream()

Constructs an unopened ofstream object.

ofstream(int fd)

Constructs an ofstream object connected to a file whose descriptor is passed through the fd argument. The file must already be open.

ofstream(int fd, char *p, int len)

Constructs an ofstream object connected to a file whose descriptor is passed through the fd argument, and also initializes the associated filebuf object to use the len bytes starting at p as the reserve area. If p is null or len is 0, the filebuf object is unbuffered.

ofstream(const char *name, int mode, int prot)

Constructs an ofstream object and opens the file specified by the name argument. The mode and prot arguments specify the file open mode and protection. By default, prot is filebuf::openprot . If the open fails, the error state ( io_state ) of the constructed ofstream object indicates failure.

~ofstream()

Deletes an ofstream object.

Member Functions

void attach(int fd)

Connects an ofstream object to a file whose descriptor is passed through the fd argument. A failure occurs when the ifstream object is connected to a file, in which case ios::failbit is set in the ofstream object error state.

void close()

Closes any associated filebuf object and consequently breaks the connection of the ofstream object to the file. The error state of the ofstream object is cleared except on failure. A failure occurs when the call to the filebuf object close() function fails.

void open(const char *name, int mode, int prot)

Opens a file specified by the name argument and connects the ofstream object to it. If the file does not exist, the function tries to create it with the protection specified by the prot argument unless ios::nocreate is set. By default, prot is filebuf::openprot .

Failure occurs if the ofstream object is open or when the call to the filebuf object open() function fails, in which case ios::failbit is set in the filebuf object's error state. The members of open_mode are bits that may be joined together by or (and because this joining takes an int , open() takes an int rather than an open_mode argument). For an explanation of the meanings of these bits in open_mode , see the Enumerated Types section for the ios class.

filebuf *rdbuf()

Returns a pointer to the filebuf object associated with the ofstream object. This function has the same meaning as ios::rdbuf() , but has a different type.

void setbuf(char *p, int len)

Calls the associated filebuf object setbuf() function to request space for a reserve area. A failure occurs if the filebuf object is open or if the call to rdbuf()->setbuf fails for any other reason.

OMANIP(TYPE) class

For an ostream object, declares predefined parameterized manipulators and provides macros for user-defined parameterized manipulators.

Header File

#include <iomanip.hxx>

Alternative Header

#include <iomanip.h>


Compile-Time Parameter

TYPE---The type of the ostream object. It must be an identifier.

Declaration


class OMANIP(TYPE) 
{ 
public: 
    OMANIP(TYPE)(ostream &(*f)(ostream &, TYPE), T a ); 
    friend ostream &operator<<(ostream & s, OMANIP(TYPE) &m); 
}; 


Description

These manipulators serve the ostream class by producing some useful effect, such as embedding a function call in an expression containing a series of insertions and extractions. You also can use manipulators to shorten the long names and sequences of operations required by the ostream class.

In its simplest form, a manipulator takes an ostream& argument, operates on it in some way, and returns it.


Constructor

OMANIP(TYPE)(ostream &(*f)(ostream &, TYPE), T a )

Creates a manipulator.

Operator

ostream &operator << (ostream & s, OMANIP(TYPE) &m)

Sends data to an ostream object.

ostream class

Supports insertion into streambuf objects.

Header File

#include <iostream.hxx>

Alternative Header

#include <iostream.h>


Declaration


class ostream : virtual public ios 
{ 
public: 
                        ostream(streambuf *); 
    virtual             ~ostream(); 
 
    ostream             &flush(); 
    int                 opfx(); 
    void                osfx(); 
    ostream             &put(char c); 
    ostream             &seekp(streampos); 
    ostream             &seekp(streamoff, seek_dir); 
    streampos           tellp(); 
    ostream             &write(const char *ptr, int n); 
    inline ostream      &write(const unsigned char *ptr, int n); 
    ostream             &operator<<(const char *); 
    ostream             &operator<<(char); 
    inline ostream      &operator<<(short); 
    ostream             &operator<<(int); 
    ostream             &operator<<(long); 
    ostream             &operator<<(float); 
    ostream             &operator<<(double); 
    ostream             &operator<<(const unsigned char *); 
    inline ostream      &operator<<(unsigned char); 
    inline ostream      &operator<<(unsigned short); 
    ostream             &operator<<(unsigned int); 
    ostream             &operator<<(unsigned long); 
    ostream             &operator<<(void *); 
    ostream             &operator<<(streambuf *); 
    inline ostream      &operator<<(ostream &(*f)(ostream &)); 
    ostream             &operator<<(ios &(*f)(ios &)); 
 
protected: 
                        ostream(); 
}; 


Description

Objects of this class perform formatted and unformatted insertions into streambuf objects.

Constructors and Destructors

ostream(streambuf *b)

Constructs an istream object. It initializes ios state variables and associates the buffer b with the ostream object.

virtual ~ostream()

Deletes an ostream object.

Overloaded Operators

The following operators are all formatted output inserters. Given the expression outs << x, these operators insert into outs. rdbuf() a sequence of characters representing x. The argument to the operator determines the type of x. Insertions are performed after a call to outs. opfx() only if that call returns nonzero. Errors are indicated by setting the error state of the ostream object. The ostream object is always returned.

Conversion of x to a sequence of characters depends on the type of x and on the values of the ostream object's format state flags and variables. Padding occurs after this representation is determined. If width() is greater than 0, and the representation contains fewer than width() characters, then the function adds enough fill() characters to bring the total number of characters to ios::width() . If ios::left() is set, the sequence is left-adjusted; that is, the function puts the padding after the sequence of characters. If ios::right() is set, the padding is added before the character sequence. If ios::internal() is set, the padding is added after any leading sign or base indication and before the characters that represent the value. ios::width() is reset to 0 but all other format variables are unchanged. The full sequence (padding plus representation) is inserted into the ostream object rdbuf() function.

ostream &operator << (char x)

ostream &operator << (unsigned char x)

Inserts a character x. No special conversion is needed.

ostream &operator << (const char *x)

ostream &operator << (const unsigned char *x)

Inserts a sequence of characters up to (but not including) the terminating null of the string that x points at.

ostream &operator << (short x)

ostream &operator << (int x)

ostream &operator << (long x)

ostream &operator << (unsigned short x)

ostream &operator << (unsigned int x)

ostream &operator << (unsigned long x)

Inserts characters as follows:

ostream &operator << (float x)

ostream &operator << (double x)

Converts the arguments according to the current values of the ostream object's precision() function, the ostream object's width() function, and the ostream object's format flags: ios::scientific , ios::fixed , and ios::uppercase . The default value for the ostream object's precision() function is 6. If neither ios::scientific nor ios::fixed is set, the value of x determines whether the representation uses scientific or fixed notation.

ostream &operator << (void *v)

Converts pointers to integral values and then converts them to hexadecimal numbers as if ios::showbase was set.

ostream &operator << (streambuf *sb)

Given the expression outs << sb, inserts into sb. rdbuf() the sequence of characters that can be fetched from sb. When no more characters can be fetched from sb, insertion stops. This function does no padding. It always returns the ostream object.

ostream &operator << (ios &(*f)(ios &))

Calls an ios object manipulator function f for an ostream object.

ostream &operator << (ostream &(*f)(ostream &))

Calls an ostream object manipulator function f for an ostream object.

Other Member Functions

ostream &flush()

Calls the ostream object's rdbuf()->sync() function to consume (that is, write to the external file) any characters that may have been stored into a streambuf object but are not yet consumed.

int opfx()

Performs output prefix actions. If the error state of the ostream object is nonzero, it returns immediately. If the value of the ostream object's tie() function is not null, it is flushed. The function returns nonzero except when the error state of the ostream object is nonzero.

void osfx()

Performs output suffix actions before returning from inserters. If ios::unitbuf is set, this function flushes the ostream object. If ios::stdio is set, the function flushes stdout and stderr . It is called by all predefined inserters, and should also be called by user-defined inserters after any direct manipulation of the streambuf object. It is not called by the binary output functions.

ostream &ostream::put(char c)

Inserts c into the ostream object's rdbuf() function. It sets the error state if the insertion fails.

ostream &seekp(streampos)

ostream &seekp(streamoff, seek_dir)

Repositions the put pointer of the ostream object's rdbuf() function.

streampos tellp()

Returns the current position of the put pointer belonging to the ostream object's rdbuf() function.

ostream &write(const char *ptr, int n)

ostream &write(const unsigned char *ptr, int n)

Inserts the n characters starting at ptr into the ostream object's rdbuf() function. These characters may include zeros; that is, ptr need not be a null-terminated string.

Example


char c = 'Z'; 
cout.put(c); 
      

Inserts a single character ( Z ) into cout .


See Also

ostream_withassign class
ostrstream class

ostream_withassign class

Adds an assignment operator and a constructor with no operands to the ostream class.

Header File

#include <iostream.hxx>

Alternative Header

#include <iostream.h>


Declaration


class ostream_withassign: public ostream 
{ 
public: 
                        ostream_withassign(); 
    virtual             ~ostream_withassign(); 
 
    ostream_withassign  &operator=(ostream &); 
    ostream_withassign  &operator=(streambuf *); 
}; 
 


Description

This class adds an assignment operator and a constructor with no operands to the ostream class.

Constructors and Destructors

ostream_withassign()

Constructs an ostream_withassign object; it does no initialization.

virtual ~ostream_withassign()

Deletes an ostream_withassign object; no user action is required.

Overloaded Operators

ostream_withassign &operator = (ostream &s)

Associates s. rdbuf() with the ostream_withassign object and initializes the entire state of that object.

ostream_withassign &operator = (streambuf *sb)

Associates sb with an ostream_withassign object and initializes the entire state of that object.

ostrstream class

Supports the insertion of characters into arrays of bytes in memory.

Header File

#include <strstream.hxx>

Alternative Header

#include <strstream.h>


Declaration


class ostrstream: public ostream 
{ 
 
public: 
                      ostrstream(); 
                      ostrstream(char *, int, int = ios::out); 
                      ~ostrstream(); 
 
     int              pcount(); 
     strstreambuf     *rdbuf(); 
     char             *str(); 
}; 


Description

This class specializes the ostream class for in-core operations by providing members that insert characters into arrays of bytes in memory.

Constructors and Destructors

ostrstream()

Constructs an ostrstream object and dynamically allocates space to hold stored characters.

ostrstream::ostrstream(char *cp, int n, int mode)

Constructs an ostrstream object and stores characters into the array starting at cp and continuing for n bytes. If ios::ate or ios::app is set in mode, the function takes cp to be a null-terminated string and it begins storing at the null character; otherwise, it begins storing at cp. Seeks are allowed anywhere in the array.

~ostrstream()

Deletes an ostrstream object.

Member Functions

int pcount()

Returns the number of bytes that have been stored into the buffer. This function is useful when binary data has been stored and the ostrstream object str() function does not point to a null-terminated string.

strstreambuf *rdbuf()

Returns the strstreambuf associated with the ostrstream object.

char *str()

Returns a pointer to the array being used and freezes the array. After str() has been called, the effect of storing more characters into the strstream object is undefined. If the strstream object was constructed with an explicit array, the function returns a pointer to the array; otherwise, it returns a pointer to a dynamically allocated area. Until str() is called, deleting the dynamically allocated area is the responsibility of the strstream object. After str() returns, dynamic allocation becomes the responsibility of the user program.

Example


char *bptr = bf.str()                                    
      

Initializes the variable bptr with the address of the array associated with the ostrstream object bf . This lets you manipulate the array through bptr just as you would any character array.


Previous Next Contents Index
  

1.800.AT.COMPAQ

privacy and legal statement