🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #515

(none)

#515
From: gswang
Date: Tue, 29 Sep 1992 15:22
78 lines
2619 bytes
To:bug-gcc@prep.ai.mit.edu
cc:gswang&cs.unlv.edu
Subject:bug
--------

   I am working on a project with G++. When I try to stream 

a object into file, I find some member function of iostrem does 

not  work correctly.

     First I wrote 2 objects into file then read them back.

Everything is wrong. I want know where this bug come from? 

from my code ? or from the compiler?

     Please send me mail and tell me what is wrong ASAP, because I can 

not  make any progress on my project before this is done.

    I appreciate your time!


    the following is the code and output:




#include <std.h>
#include <fstream.h>
#include <iostream.h>
class people{
public:
  char name[20];
  long ssn;
  people(char *n,long num){ memset (name,0,20);strcpy(name,n);}
};
int main()
{ people p0("",0);
  people p1("joe",12342);
  people p2("jery",345435);
  ofstream out("file");
  out.write((char *)&p1,sizeof(p1));
  out.write((char *)&p2,sizeof(p2));
  long pos=out.tellp();
  cout<<"position after write 2 people="<< pos<<"\n";
  out.close();

  ifstream input("file");
  input.read((char *)&p0,sizeof(p0));
  cout << "This is what is red from the file :  "<< p0.name <<" "<<p0.ssn<<"\n";
    return 0;
}



mayall% g++ -v cpptest.cc
Reading specs from /local/gnu/lib/gcc/sparc-sun-sunos4.1.1/2.1/specs
gcc version 2.1
 /local/gnu/lib/gcc/sparc-sun-sunos4.1.1/2.1/cpp -lang-c++ -v -undef -D__GNUC__=
2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix
__ -D__sparc -D__sun -D__unix cpptest.cc /usr/tmp/cc021848.i
GNU CPP version 2.1 (sparc)
 /local/gnu/lib/gcc/sparc-sun-sunos4.1.1/2.1/cc1plus /usr/tmp/cc021848.i -quiet
-dumpbase cpptest.cc -version -o /usr/tmp/cc021848.s
GNU C++ version 2.1 (sparc) compiled by GNU C version 2.1.
 as -o cpptest.o /usr/tmp/cc021848.s
 /local/gnu/lib/gcc/sparc-sun-sunos4.1.1/2.1/ld -e start -dc -dp /lib/crt0.o -L/
local/gnu/lib/gcc/sparc-sun-sunos4.1.1/2.1/ -L/local/gnu/lib/ cpptest.o -lg++ -l
gcc -lc -lgcc
mayall% a.out
position after write 2 people=0
This is what is red from the file :  jjoe 0
 

    (the position should be a number greater than 0)                     
    (the output "jjoe 0 "should be "joe 12342")
Technical Details
Message-ID: <9209300529.AB04462@life.ai.mit.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mayall.cs.unlv.edu!gswang

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!mayall.cs.unlv.edu!gswang
From: gswang@mayall.cs.unlv.edu
Subject: (none)
Message-ID: <9209300529.AB04462@life.ai.mit.edu>
Sender: daemon@cis.ohio-state.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 29 Sep 1992 15:22:00 GMT
Lines: 78