// file: $isip/doc/examples/class/io/io_example_00/example.cc // version: $Id: example.cc 5940 2000-12-17 17:07:09Z hamaker $ // // isip include files // #include #include #include #include // main program starts here: // this program reads long integer entries from a text Sof file and prints // each one found // int main(int argc, const char **argv) { // declare an Sof file object // Sof sof1; // open a file in read only mode: // note that the Sof object determines whether the input file is text or // binary automatically. in this example, it happens to be text. // String filename(L"./file.sof"); sof1.open(filename, File::READ_ONLY); // declare a Long object used to read from the Sof file // Long j; // loop through all Long objects in the file, starting with the first // and ending when we have visited all objects with the given name // note that the sof1 object is looking up the object based on its name // which, in this case, is "Long". one could uniquely determine each Long // object in the file by assigning each a different name and using that // name to read in the object rather than the default name. // long tag = sof1.first(j.name()); while (tag != Sof::NO_TAG) { // have the object read itself: // this calls the Long::read method. each object in the math library // and above knows how to read itself from an Sof file // j.read(sof1, tag, j.name()); // output the object to the console // String output; output.assign(j); output.insert(L"I found the value " , 0); Console::put(output); // go to the next object // tag = sof1.next(j.name(), tag); } // close the input file // sof1.close(); // exit gracefully // Integral::exit(); }