conexus logo

file_eof.cpp

Conexus::File EOF handling example

/***************************************************************************
 *   Copyright (C) 2001 by Rick L. Vinyard, Jr.                            *
 *   rvinyard@cs.nmsu.edu                                                  *
 *                                                                         *
 *   This file is part of the conexus library.                             *
 *                                                                         *
 *   The conexus library is free software; you can redistribute it and/or  *
 *   modify it under the terms of the GNU General Public License version 3 *
 *   as published by the Free Software Foundation.                         *
 *                                                                         *
 *   The conexus library is distributed in the hope that it will be        *
 *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty   *
 *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
 *   General Public License for more details.                              *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this software. If not see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/
#include <conexus.h>

#include <iostream>

int main(int argc, char* argv[]) {
  Conexus::Data d;

  Conexus::init();

  Conexus::File::pointer file = Conexus::File::create("test.txt", Conexus::FILE_READ);

  while (1) {
    try {
    d = file->read(1);
      std::cout << d[0];
    }
    catch ( Conexus::exception::read::eof )
    {
      break;
    }
  }

  file->close();

  file->open();
  file->set_throw_eof(false);

  while ( ! file->eof() ) {
    d = file->read(1);
    if ( d )
      std::cout << d[0];
  }

  file->close();

  return 0;
}

Generated on Wed Jul 8 15:50:07 2009 for conexus by doxygen 1.5.8