Discussion Community

IT Acumens Forum => Programming Discussions for Engineers => Programming in "Vc++" => Topic started by: thiruvasagamani on Aug 15, 2008, 04:47 PM

Title: Saving Values in Binary Format
Post by: thiruvasagamani on Aug 15, 2008, 04:47 PM
To indicate that you want to save a value as binary, when declaring the ofstream variable, specify the ios option as binary.

Here is an example:

Code: [Select]
#include <fstream>
#include <iostream>
using namespace std;

class Student
{
public:
char   FullName[40];
char   CompleteAddress[120];
char   Gender;
double Age;
bool   LivesInASingleParentHome;
};

int main()
{
Student one;

strcpy(one.FullName, "Ernestine Waller");
strcpy(one.CompleteAddress, "824 Larson Drv, Silver Spring, MD 20910");
one.Gender = 'F';
one.Age = 16.50;
one.LivesInASingleParentHome = true;

ofstream ofs("fifthgrade.ros", ios::binary);

return 0;
}
Title: Re: Saving Values in Binary Format
Post by: nandagopal on Jan 16, 2009, 04:11 AM


nice code and but need explanation mani please post with explanation   
Title: Re: Saving Values in Binary Format
Post by: dwarakesh on Jan 20, 2009, 07:18 PM
Hi mani

   I can't understand this particular coding

  ofstream ofs("fifthgrade.ros", ios::binary);

  Can you explain