File Handling in c++ Programs Using Class[Latest ] Beginners Guide

What Is File Handling

The process in which we can save the entered data permanent on disk in the form of files it is known as file handling 


They are two types of files in which we can do file handling

1:- Binary files

2:- Txt files

Binary files 
In this form of file handling we can store data and  benefit is that data will be stored as unseen character which is not seen and only numeric number will be seen and extenion of binary file is .dat
Txt files
In this form of files data will be shown easily in files 
In this form we can see all characters in files 

Critically Differentiate B/w Binary Files And Text Files

In binary files data can be consist of unread characters and only numeric data will be read

In txt files all data consist of readable character In text files we can easily read data in files

Explanation

For storing the data on disk in form of file we use the headrel File 

#include<fstream.h>

for only  writing data in file

we used ofstream
For only reading data from file
we used ifstream
And For Both Read and Write data in files we used
fstream

Example of File Handling (Writing Data )

#include<iostream.h>

#include<conio.h>

#include<fstream.h>

void main ()

{

int a;

char b;

cout<<"Plz Enter the Name";

cin>>b;

cout<<"Plz Enter the Age";

cin>>a;

ofstream f;

f.open("ali.txt",ios::app|ios::ate);

f<<a;

f<<b;

getch();

}

(Try on your Compiler )

Best Of Luck

No comments:

Post a Comment