Input and Output in C-XSC



next up previous
Next: Error Handling in Up: C-XSC Previous: Dynamic Multiple-Precision Arithmetic

Input and Output in C-XSC

Using the stream concept and the overloadable operators << and >> of C++, C-XSC provides rounding and formatting control during I/O (input/output) for all new data types, even for the dotprecision and multiple-precision data types. I/O parameters such as rounding direction, field width, etc. also use the overloaded I/O operators to manipulate I/O data. If a new set of I/O parameters is to be used, the old parameter settings can be saved on an internal stack. New parameter values can then be defined. After the use of the new settings, the old ones can be restored from stack. The following example illustrates the use of the C-XSC input and output facilities:

main()
{
  real a, b;
  interval c;

  cout << "Please enter real a, b: ";
  cout << RndDown;
  cin  >> a;                    /* read a rounded downwards      */
  cout << RndUp;
  cin  >> b;                    /* read b rounded upwards        */
  "[0.11, 0.22]" >> c;          /* string to interval conversion */
  cout << SaveOpt;              /* save I/O parameters to stack  */
  cout << SetPrecision(20,16);  /* set field width and digits    */
  cout << Hex;                  /* hexadecimal output format     */
  cout << c << RestoreOpt;   /* reload old parameters from stack */
}


Andreas Wiethoff
Wed Mar 29 13:50:24 MET DST 1995