Jump to content

Deleting from a file

- - - - -

  • Please log in to reply
1 reply to this topic

#1
hbk

hbk

    Learning Programmer

  • Members
  • PipPipPip
  • 71 posts
I have the code below but iits not deleting the selected data from file

This is the data in the file

1 Single.Standard Standard Empty ......... ........ 70

2 Single Standard Empty ........ ....... 70 




while(!file.eof())

		{				

			

			file >> roomnumber >> category >> type >> status >> datein >> dateout >> rate ;


			data.setroominfo(roomnumber,category,type,status,datein,dateout,rate);


			if(roomid!=data.getroomnumber())	

			{

				fstream file3;


				file3.open("temp.txt",ios::out|ios::app);

				

				file3 << roomnumber << ' ' << category << ' ' << type << ' ' << status <<  ' ' << datein << ' ' << dateout << ' ' << rate << endl;	

				


				file.close();

				file3.close();

			}

						


			remove("room.txt");

			rename("temp.txt","room.txt");		

				

			cout<<"\nRoom has been removed";


				break;

			

		}



#2
zoranh

zoranh

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
You're reading roomnumber from file, but comparing roomid in the if statement. I suppose that if statement should look like:
if (roomnumber != data.getroomnumber())





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users