CMPT 212 asgn4 hint

David Simpson (simpson@cs.sfu.ca)
Wed, 25 Mar 1998 11:55:29 -0800 (PST)


 To use the display() function for an "expr", you can pass it an
 "ostrstream", which is a "string stream".  The "ostrstream" class
 has two member functions which you can use:
    ostrstream::str()       - returns a pointer to the string.
    ostrstream::pcount()    - returns the number of character in the
				 string.
 These two values can be used in the call to the "TextOut" function.

 The reason that you can pass an "ostrstream" instance to the 
 display() function is that display() expects an "ostream" instance,
 and the "ostrstream" class is derived from the "ostream" class, so
 every "ostrstream" instance is an "ostream" instance.

 One problem: you have to clear the string between each output.
 There are two ways of doing this.  First, you can call a member
 function of "ostrstream" to empty the string.  I'm not sure if such
 a function exists.  If you find one, let me know.  Second, you can
 allocate a new "ostrstream" instance for each output, then delete
 it when you are done with it.  This is somewhat inefficient, but 
 it works.  In this case, you will need to have a pointer to an
 "ostrstream" instance.

  - Dave Simpson
    CMPT 212 instructor