Vous êtes sur la page 1sur 4

#include<fstream.

h>
#include<conio.h>
#include<stdio.h>
void Write_file()
{
char line[80];
ofstream f1,f2;
f1.open("temp1.txt");

if(!f1)
{
cout<<"file cant be created\n";
return;
}
cout<<"Plse enter text \n";
char ch;
do
{
cout<<"enter information\n";
gets(line);
f1<<line<<"\n";
cout<<"Do you wish to enter more lines\n";
cin>>ch;
}
while(ch=='y'||ch=='Y');
f1.close();
getch();
}
void Alternate()
{
ofstream f1,f2;
char line[80];

ifstream fin;
f1.open("Alt1.txt");
f2.open("Alt2.txt");
fin.open("temp1.txt");
fin.seekg(0);
while(!fin.eof())
{
fin.getline(line,80);
f1<<line<<"\n";
fin.getline(line,80);
f2<<line<<"\n";
}
fin.close();
f1.close();
f2.close();
getch();

}
void Read_file()
{
ifstream f1,f2;
char line[80];
f1.open("Alt1.txt");
f2.open("Alt2.txt");
f1.seekg(0);
f2.seekg(0);
while(!f1.eof())
{
f1.getline(line,80);
cout<<line<<"\n";
getch();
}

while(!f2.eof())
{
f2.getline(line,80);
cout<<line<<"\n";
getch();
}
f1.close();
f2.close();
}

void main()
{

Write_file();
Alternate();
Read_file();
getch();
}

Vous aimerez peut-être aussi