Write a program to create a file “st.txt” and store student information into it using<


 

/* Write a program to create a file “st.txt” and store student information into it using<<operator*/

#include<fstream.h>

#include<process.h>

#include<conio.h>

void main()

{

clrscr();

int rollno;

char name[20];

int marks;

ofstream out_file(“st.txt”);

if(!out_file)

{

cerr<<“file cannot open”;

exit(-1);

}

cout<<“enter student detail”<<endl;

cout<<“enter rollno=”;

cin>>rollno;

cout<<“enter name=”;

cin>>name;

cout<<“enter marks=”;

cin>>marks;

cout<<“writing student detail into file”;

out_file<<rollno<<endl;

out_file<<name<<endl;

out_file<<marks<<endl;

getch();

}

/* output:

enter student detail

enter rollno=1

enter name=ram

enter marks=90

writing student detail into file*/

Related Posts

Comments are closed.