Write a
program to illustrate the use of put(), get() and getline() functions for
Text mode Input/Output.
|
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
void main()
{
//demo
on std io devices
clrscr();
/*char
ch;
cout<<"\n
Enter character";
cin.get(ch);
cout<<"\n
The character is";
cout.put(ch);
char
ch1[50];
cout<<"\n
Enter string";
cin.getline(ch1,4,'#');
cout<<"\n
Your String is "<<ch1<<endl;
//demo
on text mode io
char
fch='a',fch1;
ofstream
of1("demo.txt");
of1.put(fch);
of1.close();
cout<<"\n
Read data from file \n";
ifstream
if1("demo.txt");
if1.get(fch1);
cout<<fch1;
if1.close();
cout<<"\n
Write line and read from file\n";
ofstream
of11("demo1.txt");
for(char
i='a';i<'z';i++)
{
of11<<i;
}
of11.close();
char
fc[50];
ifstream
if11("demo1.txt");
if11.getline(fc,10,'#');
cout<<fc;
if11.close();
getch( );
}