i have problem , i want to modify a file without copy to another file so any one can give how to do it ? I tried following method to modify a given location or pointer in file but did not work .
When you said "did not work", please be specific. I know what happened, but that's only because I can deduce it due to experience. Not everyone may be able to immediately call from memory that opening a file in write mode will truncate the file to 0 bytes. You can open the file in read-write (aka. update) mode to get the correct behavior:
ofstream outfile("test.txt", ios::in | ios::out);
Note that this method only way that works is if you perfectly overwrite what's already there. If the overwriting data is shorter or longer by even a single character, it "doesn't work". ;)
thanks but when i opened the file in input output bothmode like below
fstream iout ;
than also not work .
You did read the part where I said "does not work" is not helpful, right? If my suggestion doesn't work then the problem is elsewhere, and likely due to you failing to provide sufficient information about your problem.
You cannot just open a file for read+write, seek to some position, write some data, and expect it to move all the rest of the file's data down - it will be overwritten... You have to write the rest of the file's data the from the location you are going to insert the new data to the position just past the length of the new data, and then re-seek to the that position and write the new data. This is a major PITA honestly, and the source of a LOT of data errors! The ONLY reason to NOT write to a second file is because you are short of disc space, because doing that is a lot easier and less error prone.
This is a good example of violating the KISS principle! :-)
when file system is overwriting at given pointer location than file is truncated (the data what ever after the given pointer or seek postion ).there is any method to overwriting data which is shorter or longer .Below is my code if there is any correction than tell me .
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...