i'm puzzled.
ok so, i have a file, text type.
actually it's a type of list.. here i'll give u an expample..
dudes
1,3,4,
more dudes
2,5,6,
a list of ppl grouped to groups.
my problem has to do with adding ppl, numbers, to these lists
dudes
1,3,4,7,
more dudes
2,5,6,
so, i try to do this without rewriting the whole file. i just can't do this, is there any way?
if i can't my solution would be to read the file into a buffer to the point where the dude needs to be added, in this case
"dudes
1,3,4,"
add to the buffer
"7,"
add the rest of the file to the buffer
"
more dudes
2,5,6
"
and then use ios::trunc to write the file anew..
C++
Moderator: Moderators
- KiviGerbil
- Posts: 56
- Joined: 27 Jun 2005, 17:27
- KiviGerbil
- Posts: 56
- Joined: 27 Jun 2005, 17:27
Post the code
I think it would help clarify if you posted the code! If I understand what you're asking (and I may well have misunderstood, because it's hard to understand what some of the things in your post mean) your question isn't about C++ but about the way that files work on computers. You're basicallly asking if you've got a text file containing some text, is there a way to insert stuff into the middle of the file without rewriting the file?
The answer is no. The reason is that the file is written down on your hard drive one byte after another. Imagine if you wrote the file out by hand on a piece of paper and you wanted to insert something half way through. Where would you put the extra stuff? You just can't do it, there isn't physically any room to do it, so yes, you need to rewrite the file. The best you can get away with is to just rewrite the file from the insertion point onwards.
However it may be that there are other issues here - care to expand on what it is you're doing? (and maybe post some code - not forgetting to put it in a "code" block)
I hope this helps
Cheers
Munch
The answer is no. The reason is that the file is written down on your hard drive one byte after another. Imagine if you wrote the file out by hand on a piece of paper and you wanted to insert something half way through. Where would you put the extra stuff? You just can't do it, there isn't physically any room to do it, so yes, you need to rewrite the file. The best you can get away with is to just rewrite the file from the insertion point onwards.
However it may be that there are other issues here - care to expand on what it is you're doing? (and maybe post some code - not forgetting to put it in a "code" block)
I hope this helps
Cheers
Munch
- KiviGerbil
- Posts: 56
- Joined: 27 Jun 2005, 17:27