I/O Examples

#include "io.h"

int main( int argc, char** argv ) {

We begin each example by creating the input stream. Next, we initialize the string we expect suplib::getrecord to return. Finally, we call getrecord and compare the returned string to the expected string.

  {
    // Example 1
    strstream strstr; 
    strstr <<  "  now, is, the, time  ";
    expected = "  now, is, the, time  ";
    suplib::getrecord( strstr, returned, suplib::READ_PHYS );
    cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
  }
With suplib::READ_PHYS set, we read up until the `\n' or EOF.

  {
    // Example 2
    strstream strstr;
    strstr <<  "  now, is, the, time  \n";
    expected = "  now, is, the, time";
    suplib::getrecord( strstr, returned, suplib::READ_PHYS | suplib::STRIP );
    cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
  }
With suplib::READ_PHYS and suplib::STRIP set, we read up until the `\n' and then strip all whitespace from the end of the string.

  {
    // Example 3
    strstream strstr;
    strstr <<   "  now, is, the, time  \\  \n" 
           <<   "  now, is, the, time  \\  \n" 
           <<   "  now, is, the, time  ";
    expected  = "  now, is, the, time  ";
    expected += "  now, is, the, time  ";
    expected += "  now, is, the, time  ";
    suplib::getrecord( strstr, returned, suplib::READ_LOGICAL );
    cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
  }
With suplib::READ_LOGICAL set, we read all three physical lines.

  {
    // Example 4
    strstream strstr; 
    strstr   << "  now, is, the, time  \\  \n"
             << "  now, is, the, time  \\  \n"
             << "  now, is, the, time  ";
    expected  = "  now, is, the, time  \\\n";
    expected += "  now, is, the, time  \\\n";
    expected += "  now, is, the, time  ";
    suplib::getrecord( strstr, returned, suplib::READ_LOGICAL | suplib::CLEAN );
    cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
  }
With suplib::READ_LOGICAL and suplib::CLEAN set, we read all three physical lines and remove whitespace between the continuation character and the newline character.

  {
    // Example 5
    strstream strstr; 
    strstr  << "  now, is, the, time  \n";
    expected = "  now, is, the, time";
    suplib::getrecord( strstr, returned, suplib::READ_LOGICAL | suplib::STRIP );
    cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
  }
With suplib::READ_LOGICAL and suplib::STRIP set, we read the single physical line since there is no continuation character. We then strip the trailing whitespace from the line.

  {
    // Example 6
    strstream strstr;
    strstr <<   "  now, is, the, time  \\  \n"
           <<   "  now, is, the, time  \\  \n"
           <<   "  now, is, the, time  ";
    expected  = "  now, is, the, time  ";
    expected += "  now, is, the, time  ";
    expected += "  now, is, the, time";
    suplib::getrecord( strstr, returned, suplib::READ_LOGICAL | suplib::STRIP);
    cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
  }
With suplib::READ_LOGICAL and suplib::STRIP set, we read the three physical lines. We then strip the continuation character and trailing whitespace from the line.

  {
    // Example 7
    strstream strstr;
    strstr << "  now, is, the, time  \\  \n"
           << "  now, is, the, time  \\  \n"
           << "  now, is, the, time  ";
    expected  = "  now, is, the, time  \\\n";
    expected += "  now, is, the, time  \\\n";
    expected += "  now, is, the, time";
    suplib::getrecord( strstr, returned, suplib::READ_LOGICAL | suplib::STRIP | suplib::CLEAN );
    cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
  }
With suplib::READ_LOGICAL, suplib::STRIP, and suplib::CLEAN set, we read the three physical lines. We then strip the continuation character and trailing whitespace from the line.

  {
    // Example 8
    strstream strstr;
    strstr   << "  now, is, the, time  -  \n"
             << "  now, is, the, time  -  \n"
             << "  now, is, the, time  ";
    expected  = "  now, is, the, time  ";
    expected += "  now, is, the, time  ";
    expected += "  now, is, the, time  ";
    suplib::getrecord( strstr, returned, suplib::READ_LOGICAL, '\n', '-' );
    cout << ( returned == expected ? "OK" : "NOT OK" ) << endl;
  }
Here we change the definition of the continuation character.

}

Generated on Thu Oct 2 20:49:06 2008 for suplibxx by  doxygen 1.5.6