This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Behavior of ifstream::read() in g++


This program has different behavior in
* g++ 3.4.4 (Cygwin)
* gpp 4.0.1 *Djgpp)
* Microsoft C++ 13.00.9466

------- foo.cpp ------
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

#define BUFFER_SIZE  1500
#define INPUT_FILE_NAME  "in.txt"

void foo ()
{
char cbuffer[BUFFER_SIZE];
ifstream fs (INPUT_FILE_NAME);

  fs.clear();
  fs.seekg (0, ios::beg);

  while (!fs.eof())
  {
    fs.read (cbuffer, sizeof(cbuffer));
    cout << "rdstate() = 0x" << hex << fs.rdstate() << dec << "; gcount() = " << fs.gcount() << endl;
  }
  cout << "rdstate() = 0x" << hex << fs.rdstate() << dec << endl;
}

int main ()
{
  foo ();
  return 0;
}

----------------------


Test input file can be seen at
http://groups.google.com/group/test-av/msg/0c4d3da487594ab7


Output for g++ (Cygwin)
--------------------
rdstate() = 0x6; gcount() = 1499
rdstate() = 0x6
-------------------
It seems that behavior of g++ is wrong here.


Output for gpp (Djgpp)
-------------------
rdstate() = 0x0; gcount() = 1500
rdstate() = 0x0; gcount() = 1500
rdstate() = 0x0; gcount() = 1500
rdstate() = 0x0; gcount() = 1500
rdstate() = 0x0; gcount() = 1500
rdstate() = 0x6; gcount() = 1071
rdstate() = 0x6
-------------------


Output for Microsoft C++
-------------------
rdstate() = 0x0; gcount() = 1500
rdstate() = 0x0; gcount() = 1500
rdstate() = 0x0; gcount() = 1500
rdstate() = 0x0; gcount() = 1500
rdstate() = 0x0; gcount() = 1500
rdstate() = 0x3; gcount() = 1071
rdstate() = 0x3
-------------------

 Alex Vinokur
     email: alex DOT vinokur AT gmail DOT com
     http://mathforum.org/library/view/10978.html
     http://sourceforge.net/users/alexvn





--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]