P. 1
File Handling

File Handling

|Views: 2|Likes:
Published by Arshia Gupta

More info:

Published by: Arshia Gupta on Oct 21, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

10/21/2011

pdf

text

original

#include<fstream.h> #include<conio.h> #include<stdio.

h>

class stud { int rno; char name[20]; float marks[3]; public: void getdata(); void dispdata(); }a,b; void stud::getdata() { cout<<"enter your roll number: "; cin>>rno; cout<<"enter your name: "; gets(name); cout<<"enter your marks: "; for(int i=0;i<3;i++) cin>>marks[i]; } void stud::dispdata() { cout<<"roll number: ";

f1.close(). while(1) .sizeof(a)).cout<<rno<<endl.dat". for(int i=0. f1. cout<<"marks: ". f1. puts(name). f1. cout<<"Do you want to enter more data? ". ofstream f1.write((char *)&a. cin>>ans. } while(ans=='Y'||ans=='y'). } void display() {ifstream f1.open("student.getdata(). cout<<endl. do { a. cout<<"name: ". .open("student.i++) cout<<marks[i]<<endl } void create() {char ans.i<3.dat".ios::binary|ios::in).ios::binary|ios::out).

while(1) { f1.sizeof(a)).close().ios ::binary).dat".read((char*)&a.ios::binary). else { cout<<"WANT TO INSERT IN HERE? ".open("temp.sizeof(a)).eof()) break.read((char *)&a. if(f1. . } f1.dat". else a. f2. ofstream f2.open("stud. if(f1.{ f1. } void insert() { char ans. f1.eof()) break.dispdata(). ifstream f1.

f1.i>0. for(int i=0.sizeof(b)).dat").getdata(). }} f1.open("stud. remove("stud. } f2."stud. display(). if(ans=='Y'||ans=='y') {b. cout<<"INSERT AN ELEMENT? ".sizeof(a)). char ans. if(ans=='y'||ans=='Y') { . cin>>ans. } void main() {clrscr().close().write((char*)&a.) { ifstream f1.write((char*)&b.ios ::binary).dat".dat"). rename("temp.dat". create(). f2. f2.cin>>ans.close().

} getch(). } .insert(). } else break.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->