//open multiple files for
//reading and writing purposes
#include<fstream.h>
#include<conio.h>
void main()
{
clrscr();
ofstream out;
//writing data
out.open("months");//opens file
out<<"March\n"; //writes string to the file
out<<"April\n";
out<<"May\n";
out.close();//closes the file
out.open("days");//opens another file
out<<"31\n";
out<<"30\n";
out<<"31\n";
out.close();//closes second file
//reading data
char text[20];
ifstream in;
in.open("months"); //opens file for reading
cout<<"\nMonths are\n";
while(in)
{
in.getline(text,20);
cout<<text<<"\n";
}
in.close();
in.open("days");
cout<<"\nDays are\n";
while(in)
{
in.getline(text,20);
cout<<text<<"\n";
}
in.close();
getch();
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.