help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Behavior of ifstream::read()


From: Alex Vinokur
Subject: Behavior of ifstream::read()
Date: Sat, 14 Oct 2006 16:27:29 +0200

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









reply via email to

[Prev in Thread] Current Thread [Next in Thread]