C++

C++

Post just about everything that isn't directly related to Spring here!

Moderator: Moderators

Post Reply
User avatar
KiviGerbil
Posts: 56
Joined: 27 Jun 2005, 17:27

C++

Post by KiviGerbil »

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..
User avatar
KiviGerbil
Posts: 56
Joined: 27 Jun 2005, 17:27

Post by KiviGerbil »

aw come on.. i know i'm crappy. pls help me or i will stare u dudes to stone, beware.
User avatar
Zoombie
Posts: 6149
Joined: 15 Mar 2005, 07:08

Post by Zoombie »

I'd like to help... but i think this should be in the Dev fourum! Also i dont know C++
User avatar
KiviGerbil
Posts: 56
Joined: 27 Jun 2005, 17:27

Post by KiviGerbil »

well, this is kinda off-topic. it has nothing to do with spring..
User avatar
munch
Posts: 311
Joined: 26 May 2005, 20:00

Post the code

Post by munch »

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
User avatar
KiviGerbil
Posts: 56
Joined: 27 Jun 2005, 17:27

Post by KiviGerbil »

yah, i thought as much. i have allready made the necceseary code to deal with this, now i need to make it read stuff and organize it.

just need to get my brains working.. maybe a game of spring will help me :-)
Post Reply

Return to “Off Topic Discussion”