Searching...
Wednesday, 23 November 2016

File Handling in OOP

File Handling in OOP



Two types of files
1.    Text files
2.    Binary Files

File Access Method

1.    Sequential Access method
2.    Random Access Method

Stream

Series of bytes is known as stream.
Types Of Stream
1.    Input stream
Reading of data from file.
2.    Output stream
Store data in file is known as output data.

Objects for stream


Cin and cout for input and output respectively.

IOS (input outut stream)

Derived classes from this are
1.    Istream
2.    Ostream

3.    Iostream
This is derived from 1 and 2.

Program:



#include<iostream>

#include<fstream>

using namespace std;

int main()
{
char name[30];

int age;

ofstream stud("c:\\student.txt");

for(int i=1; i<5 ;i++)

{

cout<<"\n Enter name=";

cin>>name;

cout<<"\n Enter age=";

cin>>age;

stud<<name<<"\t"<<age<<endl;

 

    } 
    stud.close();
}






0 comments:

Post a Comment