Headlines
Loading...
C++ program to implement streams and files in text and binary modes with object storage.

C++ program to implement streams and files in text and binary modes with object storage.

Write a C++ program to implement streams and files in text and binary modes with object storage.

PROGRAM:

TEXT MODE


#include<iostream .h="">
#include<conio .h="">
#include<fstream .h="">
#include<string .h="">
void main()
{
int j;
char ch;  //character to read
char str[]="Sies college of management studies";
clrscr();
ofstream outfile;
outfile.open("test.txt"); //create file for output
for(j=0;j<strlen binary="" ch="" character="" college="" cout="" create="" display="" each="" endl="" eof="" error="" file="" for="" getch="" ifstream="" include="" infile.get="" infile.open="" infile="" input="" iostream.h="" it="" j="" management="" mode="" n="" nfile="" of="" or="" outfile.close="" outfile.put="" output="" read="" str="" studies="" test.txt="" text.txt="" to="" until="" while="" write="" written="" www.adkool.com="" xyz="">
#include<conio .h="">
#include<fstream .h="">
#include<iostream .h="">

class person
{
protected:
char name[80];
int age;
public:
void get_data()     //get person's data from user
{
cout&lt;&lt;"\nEnter name : ";
cin&gt;&gt;name;
cout&lt;&lt;"\nEnter age : ";
cin&gt;&gt;age;
}
void show_data()         //display person's data
{
cout&lt;&lt;"\nNAME : "&lt;<name :="" age="" ch="" char="" cin="" clrscr="" cout="" create="" data="" details="" do="" enter="" file.open="" file.write="" file="" from="" fstream="" input="" ios::app="" ios::binary="" ios::in="" ios::out="" main="" more="" n="" nage="" nenter="" nwant="" output="" p1.get_data="" p1="" person="" s="" sample.txt="" sizeof="" to="" user="" void="" write="" y="">&gt;ch;
}while(ch=='y');
file.seekg(0);     //reset to start of file
file.read((char *)&amp;p1,sizeof(p1));  //read first person data
while(!file.eof())
{
cout&lt;&lt;"\n";
p1.show_data();
file.read((char *)&amp;p1,sizeof(p1));
}
cout&lt;</name></iostream></fstream></conio></strlen></string></fstream></conio></iostream>
*** PLEASE checkout the Best deals from for top sites like Amazon, Flipkart etc ***