- AIM:
To implement a C++ program to read the content of a file.
ALGORITHM:
Step 1: Include the header files
Step 2: Declare the variables.
Step 3: Get the file name to read.
Step 4: Using ifstreamin(filename) check whether the file exist.
Step 5: If the file exist then check for the end of file condition.
Step 6: Read the contents of the file.
Step 7: Print the contents of the file.
Step 8: Stop the program.
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
{
char c,fname[10];
clrscr();
cout<<"Enter file name:";
cin>>fname;
ifstream in(fname);
if(!in)
{
cout<<"File Does not Exist";
getch();
return;
}
cout<<"\n\n";
while(in.eof()==0)
{
in.get(c);
cout<<c;
}
getch();
}
SAMPLE OUTPUT:
Enter File name: one.txt
Master of Computer Applications
RESULT:
Thus a C++ program to read the content of a file is implemented successfully.
No comments:
Post a Comment