Write a program to reads the contents of a file “st.txt” using>> operator


 

/* Write a program to reads the contents of a file “st.txt” using>> operator*/

#include<fstream.h>

#include<process.h>

#include<conio.h>

void main()

{

clrscr();

int rollno;

char name[20];

int marks;

ifstream inp_file(“st.txt”);

if(!inp_file)

{

cerr<<“file cannot open”;

exit(-1);

}

cout<<“reading student detail from a file”<<endl;

inp_file>>rollno;

inp_file>>name;

inp_file>>marks;

cout<<“content of a file are”<<endl;

cout<<“rollno=”<<rollno<<endl;

cout<<“name=”<<name<<endl;

cout<<“marks=”<<marks<<endl;

getch();

}

/* output:

reading student detail from a file

contant of a file are

rollno=1

name=ram

marks=90*/

Related Posts

Comments are closed.