mercredi 9 août 2017

Getting an error using ifstream::read

I'm playing a little with ifstream on macOS with clang.

I'm trying to read the whole file using the read method:

  ifstream is(filename);
  is.exceptions(ifstream::failbit | ifstream::badbit);

  // This set up a buffer with a size of 2048 bytes.
  void *buff = XML_GetBuffer(parser, 2048);

  do {
    is.read(reinterpret_cast<char*>(buff), 2048);
    auto charBuff = reinterpret_cast<char*>(buff);
    std::cout << charBuff << std::endl;
  } while (!is.eof());
  is.close();

By processing a long file, an exception is thrown: ios_base::clear: unspecified iostream_category error

I tried to get more information with strerror(errno) but I only get : Err:Undefined error: 0

What is wrong with this code ? How could I get more information about the reason of the failure ?

Aucun commentaire:

Enregistrer un commentaire