Hi,
I just started learning C++ not long ago, and has been stucked at this problem for quite sometimes.
I have this text file which keep the records of cars.
00001 Toyota Camry
00002 Nissan Sunny
00003 Honda Accord
...
and so on
The problem is when i use ofstream class and try to make a modification to the line that i want to do a lazy deletion.
00002 Nissan Sunny -> xxxxxxxxxxxxxx (to indicate that this record is not a valid record)
00001 Toyota Camry
xxxxxxxxxxxxxxxxxxx
00003 Honda Accord
...
and so on
I ended up with file that has only the modification line and the rest was erased.
xxxxxxxxxxxxxxxxxx
I am using a fixed length record so i do know which byte to start the modification and where to stop.
Code:
ofstream ofile;
ofile.open("test.txt, ios::out);
ofile.seekp(20);
ofile.write("xxxxxxxxxxxxxx", 10 :confused: );
ofile.close();
this is something that similar to the code that exists in my program.
in summary: how do i modify a part of a text file without erasing the rest of the content. Thank you in advance, I cannot proceed with the homework if i cant solve this confusion.