Program to read an existing file by using object of fstream for reading/writing mode.

#include
#include
#include
#include

main()
{
ifstream vasu;
char fn[15],ch;
clrscr();
cout<>fn;
vasu.open(fn);
if(vasu.fail())
{
cout<<"nFile with specified name does not exist … try next attempt…";
getch();
exit(1);
}
else
{
cout<<"nnFile opened successfully ";
getch();
while(!vasu.eof())
{
ch=(char)vasu.get();
cout<<ch;

}
}
vasu.close();
getch();
}

Leave a reply