Xavax C++ Library Class Index   FAQ   Overview

Class xavax::StreamFormatter

StreamFormatter formats output for an ostream.

Constructor Summary
StreamFormatter(ostream stream)
         Construct a StreamFormatter object.

Methods Inherited From Formatter
print, print

Related Classes
Formatter, Variant

Constructor Detail


StreamFormatter(ostream stream)
Construct a StreamFormatter object.
stream - an output stream.

Example Code

#include <iostream.h>
#include "StreamFormatter.h"

int main(int argc, char** argv) {
  // Declare some local variables to demonstrate the data
  // types supported by StreamFormatter.
  const char* s = "Hello World";
  bool b = true;
  int i = 1234;
  unsigned int ui = 32767;
  double d = 1.2345;

  // Declare a formatter for the standard output stream.
  StreamFormatter stf(cout);

  // The format string prints a boolean, an integer, two
  // unsigned integers, a floating point value, and a string.
  const char* format = "bool    b = %b;\n"
                       "int     i = %d;\n"
                       "uint   ui = %u;\n"
                       "uint   ui = %x;\n"
                       "double  d = %f;\n"
                       "char*   s = %s;\n";

  // Each of the variables b, i, ui, d, and s will be
  // converted to a Variant and passed to print.
  stf.print(format, b, i, ui, ui, d, s);
  return 0;

Copyright © 2003 Xavax Inc. -- All Rights Reserved