what is wrong with the ifstream and ofstream? I had try again and again and the info shown run to infinity. :(
I tried a lot of times ady, will be glad if anyone can help, thank you :)
Sorry if its looks messy, still learning all the way.

int choice, bound, number, speed,  distance, depart, reach, hour, passport, passport1, source1, destination1, dd, dd1, mm, mm1, yy, yy1, ticketprice;
string name, name1, type, source, destination, menu, customer, contact, comment, inbound[9], outbound[9];
ifstream InBoundData, OutBoundData;
ofstream cinfo;

if(bound==1||bound==3)
    {
                          InBoundData.open("InBoundData.txt");
                          if (InBoundData.fail())
                          {
                           cerr<<"ERROR :Cannot open"<<InBoundData<<"for input."<<endl;
                           exit(-1);
                          }                                
                          cout<<"Type Speed Source Destination Distance Depart Reach Hour TicketPrice"<<endl;
                          while (!InBoundData.eof())
                          {
                          InBoundData>>type>>speed>>source>>destination>>distance>>depart>>reach>>hour>>ticketprice;
                          if (!InBoundData.eof())
                          cout<<type<<"  "<<speed<<" "<<setw(9)<<source<<" "<<setw(3)<<destination<<" "<<setw(5)<<distance<<" "<<setw(5)<<depart<<" "<<setw(2)<<reach<<" "<<setw(8)<<hour<<" "<<setw(10)<<ticketprice<<endl;                                  
                          }
                          InBoundData.close();
    }
    if(bound==2)
    {
                OutBoundData.open("OutBoundData.txt");
                if (OutBoundData.fail())
                {
                       cerr<<"ERROR :Cannot open"<<OutBoundData<<"for input."<<endl;
                       exit(-1);
                }                                
                cout<<"Type Speed Source Destination Distance Depart Reach Hour TicketPrice"<<endl;
                while (!OutBoundData.eof())
                {
                      OutBoundData>>type>>speed>>source>>destination>>distance>>depart>>reach>>hour>>ticketprice;
                      if (!OutBoundData.eof())
                      cout<<type<<"  "<<speed<<" "<<setw(5)<<source<<" "<<setw(3)<<destination<<" "<<setw(5)<<distance<<" "<<setw(5)<<depart<<" "<<setw(2)<<reach<<" "<<setw(8)<<hour<<" "<<setw(10)<<ticketprice<<endl;                                  
                }
                OutBoundData.close();
    }

while statements are incorrect.

while( InBoundData>>type )
{   
  InBoundData>>speed>>source>>destination>>
     distance>>depart>>reach>>hour>>ticketprice;
  cout<<type<<"  "<<speed<<" "<<setw(9)<<source<<" "<<setw(3)
     <<destination<<" "<<setw(5)<<distance<<" "<<setw(5)<<depart<<" "<<setw(2)
     <<reach<<" "<<setw(8)<<hour<<" "<<setw(10)<<ticketprice<<endl;
}

Edited 5 Years Ago by Ancient Dragon: n/a

This article has been dead for over six months. Start a new discussion instead.