delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/04/20/04:07:56

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <696BDC661BFCD411A8C90002A509489616DA3C@bndkcopmex01.barconet.com>
From: "Schultz, Jacob" <Jacob DOT Schultz AT barconet DOT com>
To: "'cygwin AT cygwin DOT com'" <cygwin AT cygwin DOT com>
Subject: File streams in C++
Date: Fri, 20 Apr 2001 09:58:45 +0200
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)

------_=_NextPart_000_01C0C96F.B9709590
Content-Type: text/plain

I've experianced strange problems with C++ streams when running under
Cygwin. I'm not sure whether this error relates to Cygwin or to GCC but
perhaps someone else can find out.
What happens is that the input file in not read to the end. The attached
program illustrates this (test data also included).

$ ./test
File ended after 311 bytes
File ended after 1001 bytes

The last resut if obviously the correct result.

Jacob Schultz

 <<test.cpp>>  <<test.txt>> 

------_=_NextPart_000_01C0C96F.B9709590
Content-Type: application/octet-stream;
	name="test.cpp"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="test.cpp"

/*
 * There seems to be a problem with C++ instream.get(char)
 * This program tests it and tests the C alternative
 */

#include <fstream.h>=0A=
#include <stdio.h>=0A=


int
main (int argc, char **argv)
{
  ifstream stream;
  FILE *file;
  unsigned char ch;
  unsigned long long int n=3D0;

  stream.open ("test.txt");
  if( stream.rdstate() !=3D 0 )=0A=
  {
    cerr << "Couldn't open input file" << endl;=0A=
    exit (1);
  }

  while (!stream.eof())
  {
	stream.get (ch);
	n++;
  }=0A=
  stream.close ();
  cout << "file ended after " << n << " bytes" << endl;

  n=3D0;
  file =3D fopen ("test.txt","r");
  while (!feof(file))
  {
	ch =3D fgetc (file);
	n++;
  }=0A=
  fclose (file);
  cout << "file ended after " << n << " bytes" << endl;

  return 0;
}
------_=_NextPart_000_01C0C96F.B9709590
Content-Type: text/plain;
	name="test.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename="test.txt"

AAABsywCQCMTiCOAAAABtRSCAAEAAAAAAbUjBQUFCwISAAAAAbJUYWJsZXRlbm5pcyBjb2RlZCBh
dCA4IE1icHMuCgAAAbgACABAAAABAAAKNEAAAAG1j//7mAAAAAEBcpP8T9qS0dG/fFACsizX55CJ
ZtkK04YoBS34K5JmhFITf2l5kr30yE2gA7b5QRmaabFRG94XtxEqNSvyPABT9aUYIgVoJv/p7Z6A
K/qXJnsoRqBIDkC2/YEktO9SgsMHVtF6s8y9LOhRVJI6t8n5OAiN9d5vAlqX+U8AF5FhvnPY+mJj
zh2gZoBHCgxqwQf5vdFM6OlS4+UEv/0D2/WE4lw4BeBcazZFQMg1YBUITSTnAQ2XnoE1t+T6AK/m
J+Oi4qzNoJn/owa3QBB/lIqWzgVQrQTf/Roz1b9OXZLiWlQLOQDvVvWTniyKHF2F06AHIxq8nDmZ
rx7b8Z0AV/VKgrraMibFBK/9Gerc8EH+b5OruoAieOBH/9GDYe36kWbCkh0UKLAXNjNwvSpLC5Rw
SADMKbMnYOaPPR7U7870AciZMpnFVVqagTA8uD2soA3Fz9O8NABiNHt+sMF8UpauaWHFFnAI/Rtn
mpliJVpcqJBxLjdBjhzUbo9qX+M6AJ+U0EMAZcQpN/YCPwAkY2gEH+b5Wo7iloVNWoGG+MGN+pCq
troXMo9aMoaGAQ1lUsZFCvEhD2z8sHRp89H1t+Z4AI/k2Su4hsKpm2BN/JzZoAKyPKH4IgVpQZfy
eGnN+sYsMPOGDyT6I3DllkWENUJADw+tXlg6NNfo9qd+a9AGe8YrycUGbDzofSyGMbscAC/eTpwO
RNW2HxFGQ+DG+2SS0YkWh8VSg2AAsb0EMujMWQvIp9OUhUa2xkHRsDaGtTfy2CD/V2tidBlTUIao
FNYCD/T2ip0NGaQzfU5v0pOAQv+qXpVoZtKLDIG+jaEiBGBHhBwDxso6Do2xtHtT/zHAB3yWuceo
4BWeGNx4APX0ZwqVJM2rYf+zoNb9wOTdfLVskqWSRB6jgHp7eDzKbpR6HlBChoEIeNaTMHMlo9qd
+Z4AOxKRccWgzRoCMaM9W9ACD/T3kl3iFvrkM0+DKHlBJ1b9Q2bhMmRCkLLHhAbBoxuUbI46VdDQ
Hw6DD21Mg5kbR7U387uAFol7pQCyZSyrlLxUNgeev6PGsQQf6PeZKTuKuodpQaA5LwfW/RG38Zd9
bQWP/gpvTlk4/T5EGKMCN9EbbykYNrb8bUAYi443yd4bQorT6M9W6IIP9PusDuktLK0oeAlGeoxv
0odkkPSloMp4UPh9GN3JKduRECTjrQUgAmx8sHRpNg==


------_=_NextPart_000_01C0C96F.B9709590
Content-Type: text/plain; charset=us-ascii

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple
------_=_NextPart_000_01C0C96F.B9709590--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019