News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

Saving Values in Binary Format

Started by thiruvasagamani, Aug 15, 2008, 11:17 AM

Previous topic - Next topic

thiruvasagamani

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:

#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;
}
Thiruvasakamani Karnan


nandagopal



nice code and but need explanation mani please post with explanation   



dwarakesh

Hi mani

   I can't understand this particular coding

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

  Can you explain