home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 9.ddi / IOSTRSR1.ZIP / OSTOUTST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.6 KB  |  87 lines

  1. /*[]------------------------------------------------------------[]*/
  2. /*|                                                              |*/
  3. /*|     ostoutst.cpp                                             |*/
  4. /*|                                                              |*/
  5. /*|     Class ostream                                            |*/
  6. /*|          void ostream::oststr( const char *, const char * )  |*/
  7. /*|                                                              |*/
  8. /*[]------------------------------------------------------------[]*/
  9.  
  10. /*
  11.  *      C/C++ Run Time Library - Version 5.0
  12.  *
  13.  *      Copyright (c) 1990, 1992 by Borland International
  14.  *      All Rights Reserved.
  15.  *
  16.  */
  17.  
  18. #include <ioconfig.h>
  19. #include <iostream.h>
  20. #include <string.h>
  21.  
  22. // Perform the prefix routine, output the string with any needed padding,
  23. // and perform the suffix routine.
  24. // 'd' is the data portion, 'p' is the prefix portion.
  25.  
  26. void ostream::outstr(const char *d, const char *p)
  27. {
  28.     if( opfx() )
  29.         {
  30.         int plen = p ? strlen(p) : 0;
  31.         int dlen = d ? strlen(d) : 0;
  32.         int pad = width(0) - plen - dlen;
  33.  
  34.         // pad on left (right-adjust) if needed -- the default case
  35.         if( ! (x_flags & (ios::left | ios::internal)) )
  36.             {
  37.             while( --pad >= 0 )
  38.                 {
  39.                 if( bp->sputc(x_fill) == EOF )
  40.                     {
  41.                     setstate(ios::badbit);
  42.                     break;
  43.                     }
  44.                 }
  45.             }
  46.  
  47.         // output the prefix
  48.         if( ! fail()  &&  plen )
  49.             if( bp->sputn(p, plen) != plen )
  50.                 setstate(ios::badbit);
  51.  
  52.         // internal padding if needed
  53.         if( ! fail()  &&  (x_flags & ios::internal) )
  54.             {
  55.             while( --pad >= 0 )
  56.                 {
  57.                 if( bp->sputc(x_fill) == EOF )
  58.                     {
  59.                     setstate(ios::badbit);
  60.                     break;
  61.                     }
  62.                 }
  63.             }
  64.  
  65.         // output the data
  66.         if( ! fail()  &&  dlen )
  67.             if( bp->sputn(d, dlen) != dlen )
  68.                 setstate(ios::badbit);
  69.  
  70.         // pad on right (left-adjust) if needed
  71.         if( ! fail()  &&  (x_flags & ios::left) )
  72.             {
  73.             while( --pad >= 0 )
  74.                 {
  75.                 if( bp->sputc(x_fill) == EOF )
  76.                     {
  77.                     setstate(ios::badbit);
  78.                     break;
  79.                     }
  80.                 }
  81.             }
  82.         }
  83.     osfx();
  84. }
  85.  
  86.  
  87.