Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,255 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,204 people online right now. Registration is fast and FREE... Join Now!




size of binary file

 
Reply to this topicStart new topic

size of binary file

dan_ram
14 Oct, 2008 - 07:12 AM
Post #1

D.I.C Head
**

Joined: 15 Aug, 2007
Posts: 76


My Contributions
i'm getting confused on the sizes of a file and an object that was written to it!!
this is the part of a program that i did:
CODE
struct EMPLOYEE{
   int emp_id, phno;
   char name[20],addr[50],dep[15];
   float sal;
   void accept(); //accept() has 1 variable of type char
};

CODE
void new_emp(){
  ofstream f1("emp1.dat",ios::binary|ios::app);
  EMPLOYEE s;
  s.accept();
  f1.write((char *)&s, sizeof(s));
  f1.close();
  ifstream f2("emp1.dat",ios::binary);
  int n=sizeof(f2);
  cout<<n<<endl;  //80
  n=sizeof(s);
  cout<<n<<endl;  //93
  f2.close();
}


surprisingly the size of object(struct) is 93 and that of file is 80
file is smaller than object!!!
how??? blink.gif
i'm using turbo C++ and size of int=2 bytes, char=1 byte, float=4 bytes

This post has been edited by dan_ram: 14 Oct, 2008 - 07:13 AM
User is online!Profile CardPM
+Quote Post

NickDMax
RE: Size Of Binary File
14 Oct, 2008 - 08:43 AM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
That is not how you return the size of a file... you returned the size of the ifstream object, not the file.

see the example here.
User is offlineProfile CardPM
+Quote Post

dan_ram
RE: Size Of Binary File
15 Oct, 2008 - 05:55 AM
Post #3

D.I.C Head
**

Joined: 15 Aug, 2007
Posts: 76


My Contributions
why isnt the size of the file same as that of the filestream object?
anyway, i wrote the struct object into the filestream object, so musnt they be equal?
hey thanks for the link biggrin.gif icon_up.gif

This post has been edited by dan_ram: 15 Oct, 2008 - 05:55 AM
User is online!Profile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 04:27AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month