Mar 26, 2007

File Handling in C++

File handling : to store data in a text/data file
Writing data to a text file

#include<iostream.h>
#include<conio.h>
#include<fstream.h> // file stream

main()
{
clrscr();
char name[10];
int salary;
ofstream f("unique"); // output file stream is a class name

for (int i=0; i<=4; i++)
{
cout <<"enter name :";
cin >> name;

cout << "enter salary :";
cin >> salary;
f<< name << "\t" << salary<<endl ;
}
getch();
}

// do the following things
/*
1 run the program
2 input some data
3 click file menu > dos shell
4 type the follwing command at dos prompt
type unique
it will display contents of the unique file.
*/

No comments:

Post a Comment

Infolinks In Text Ads

Total Pageviews

Powered by Blogger.

Dont Forget To Follow Us

Blog Archive