i have a .txt file which contains line of string like the below format
|111|34 sdddd| ppppp| A/C| 32| sadfd|
|4324|23 mmm| yyyyy| A/C|32| fdfffdfd|
the sixth column is the no of seats column where when i check the status of that particulat bus no 4324 it is displaying that the "seat is not available" and "available seats are 0"
In this code snippet i
i face the above problem in the "temp" variable.
please help me out.
void passenger::transaction(string bus_no,int tkt,string passenger_name,int age,string journey_date,int seat,int totalprice)
{ int temp;
string tempval,token,line;
stringstream iss;
int flag,flag1;
size_t found;
size_t found1;
fstream file("transaction.txt",ios::in);
fstream file1("t.txt",ios::out);
while(getline(file,line))
{
found=line.find(journey_date);
if(int(found)>0)
{
found1=line.find(bus_no);
if(int(found1)>0)
{
iss<<line;
while(getline(iss,token,'|'))
{
tempval=token;
}
temp=atoi(tempval.c_str());
if(temp<seat) {
cout<<"\t\tSorry! Seats Not Available Now.."<<endl;
cout<<"Available Seats are "<<temp<<endl;
}
else if(temp==0)
{
cout<<"Sorry! Seats Fully Booked"<<endl;
}
else
{
temp=temp-seat;
std::string s;
std::stringstream out;
out<<temp;
s=out.str();
line.replace(15,2,s);
cout<<"****Ticket Successfully Booked***"<<endl;