//WAP to display contents of a file using get() function.
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
int main()
{
system("cls");
char ch;
ifstream fin; //create input stream
fin.open("marks.dat", ios::in); //open file
if(!fin) //if fin stores zero i.e., false value
{
cout<<"Cannot open file!!\n";
return 1;
}
while(fin)
{ fin.get(ch); //read a character
cout<<ch; //display the character
}
fin.close();
return 0;
}
OUTPUT
No comments:
Post a Comment