Write a program to read character, integer and string from keyboard and write it in
“data.txt”
file and read from file in text mode.
|
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
void
main()
{
int i,i1;
char ch,ch1;
char s[20],s1[20];
clrscr();
cout<<"\n Enter integer
character and String";
cin>>i>>ch>>s;
fstream
fo("Data.txt",ios::out);
fo<<i<<endl;
fo<<ch<<endl;
fo<<s<<endl;
fo.close();
fstream
fi("Data.txt",ios::in);
fi>>i1;
fi>>ch1;
fi>>s1;
cout<<"\n Data from
file are \n";
cout<<i1<<"
"<<ch1<<" "<<s1;
fi.close();
getch();
}
|
File Program 2
Subscribe to:
Posts (Atom)