Write a program to read a file using get() function and write its contents to standard output device (screen)


 

/* Write a program to read a file using get() function and write its contents to standard output device (screen)*/

#include<fstream.h>

#include<process.h>

#include<conio.h>

void main()

{

clrscr();

char ch;

ifstream in1(“sitd.txt”);

cout<<“contents of file are\n”;

if(!in1)

{

cerr<<“file cannot open correct”;

exit(-1);

}

while(in1.eof()==0)

{

in1.get(ch);

cout<<ch;

}

getch();

}

/* output:

contents of file are*/

Related Posts

Comments are closed.