suplibxx  1.3.13
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";
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 ";
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 ";
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";
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";
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";
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.

}