-
Can Not Open File
Code:
[/LEFT]
if(choose=='S'||choose=='D'||choose=='T')
{
outfile.open(filename,ios::out|ios::app);
outfile.close();
infile.open(filename,ios::in);
if(!infile)
cout<<"Error opening the file"<<endl;
while(!infile.fail())
{
infile>>r_number>>r_name>>r_family>>r_city>>r_telephone>>type>>r_price>>r_time;
if(type=='S')
{
account_s++;
}
if(type=='D')
{
account_d++;
}
if(type=='T')
{
account_t++;
}
}
single=single-account_s;
doubler=doubler-account_d;
triple=triple-account_t;
infile.close();
if(n.type_room=='S')
{
if(single!=0)
{
cout<<"Total single bed room available is "<<single;
cout<<endl;
cout<<"\nHow many single bed room you need?";
cout<<endl;
cin>>number;
cout<<endl;
}
else
{
cout<<"\nSorry,No Room available.";
cout<<endl;
}
}
cin.get();
cout<<"First Name : ";
cin>>n.name;
cout<<"Family Name : ";
cin>>n.family;
cout<<"City : ";
cin>>n.city;
cout<<"Telephone : ";
cin>>n.telephone;
cout<<"Charge :";
cin>>n.cost_perday;
cout<<"Days : ";
cin>>n.time;
int flag=0;
for (int i=1;i<=number;i++)
{
cout<<"Room NO.: "<<endl;
cin>>room;
if(n.type_room=='S')
{
if(room<100 || room>199)
{
cout<<"You Should Choose The Number Between 100 And 199"<<endl;
cout<<endl;
i=i-1;
continue;
}
infile.open(filename,ios::in);
if(!infile)
cout<<"Error opening the file"<<endl;
while(!infile.fail())
{
infile>>r_number>>r_name>>r_family>>r_city>>r_telephone>>type>>r_price>>r_time;
if(room==r_number)
{
cout<<"You Should Choose Other Room.This is occupied."<<endl;
cout<<endl;
flag=1;
i=i-1;
break;
}
else
{
flag=0;
}
}
infile.close();
if(flag==1)
{
continue;
}
}
its not run well, cant open file properly, keep showing
"Error opening the file" some problem in the loop i cant find out please help
-
1) is 'filename' defined?
2) does the file exist?
-
after all i redefined fstream outfile,infile; in all the loop its finally work, but still dont know where should i really declare them, but
thx for remind
-
Try "if(infile.fail())" instead.