Amin_ch1991
دوشنبه 26 دی 1390, 21:24 عصر
سلام کد زیر چه کاری می کنه و اگه مشکلی داره چطوری برطرفش کنم؟
#include <fstream.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
void main()
{
char name[21];
ofstream file("1.txt");
if (!file)
{
cout<<"Can not open file";
exit(0);
}
cout<<"Enter CTRL+Z to end file"<<endl;
while(1)
{
cin>>name;
if(!name[0])
break;
file<<name<<' ';
}
file.close();
cout<<"input your name for search"<<endl;
char search[21];
cin>>search;
ifstream file2("1.txt")
file2>>name;
while(!file2.eof())
{
if (strcmp(search,name)==0)
{
file2.close();
ifstream x1("1.txt");
ofstream x2("2.txt");
if (!x2)
{
cout<<"Can not open file";
exit(0);
}
x1>>name;
while(!x1.eof())
{
if (strcmp(search,name)==0)
{
cout<<"Your search name is not saved in file 2"<<endl;
x1>>name;
}
else
{
x2<<name<<' ';
x1>>name;
}
x1.close();
x2.close();
return 0;
}
else
file2>>name;
file2.close();
getch();
}
#include <fstream.h>
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
void main()
{
char name[21];
ofstream file("1.txt");
if (!file)
{
cout<<"Can not open file";
exit(0);
}
cout<<"Enter CTRL+Z to end file"<<endl;
while(1)
{
cin>>name;
if(!name[0])
break;
file<<name<<' ';
}
file.close();
cout<<"input your name for search"<<endl;
char search[21];
cin>>search;
ifstream file2("1.txt")
file2>>name;
while(!file2.eof())
{
if (strcmp(search,name)==0)
{
file2.close();
ifstream x1("1.txt");
ofstream x2("2.txt");
if (!x2)
{
cout<<"Can not open file";
exit(0);
}
x1>>name;
while(!x1.eof())
{
if (strcmp(search,name)==0)
{
cout<<"Your search name is not saved in file 2"<<endl;
x1>>name;
}
else
{
x2<<name<<' ';
x1>>name;
}
x1.close();
x2.close();
return 0;
}
else
file2>>name;
file2.close();
getch();
}