Reply
C++ string iterators
Old 09-29-2005, 08:24 AM C++ string iterators
Recrehal's Avatar
Experienced Talker

Posts: 39
Location: Aachen, Germany
Let's assume we have one big string consisting of 2 smaller strings that will be seperated an a few iterators to the whole string. I'm a bit confused what will happen to my iterators when I modify the string as followed:

full_string = A1|B2
The two strings a represented by A and B, 1 and 2 are iterators.

Another iterator will go through the string, character per character, and once it reaches 2 the mess begins: 1 is replaced with "hello" while the position of 2 still has to be kept.

I'm not sure how I can assure that the position of 2 is kept correctly when the string is expanded at 1; assuming the iterator at 2 would point at the 5th element of the string (A1|B2<--) it won't point to the right character after the modification (Ahell<--o|B2).

So how can I assure that the position of 2 is kept although I'm modifying the string?

If iterator is not the thing to use here feel free to suggest something else. I just wouldn't want a pointer as it would quite obviously point to an adress which would be even trickier to correct as the string doesn't need to be kept in one place of the memory but could scatter trough the memory (it's a pretty large string).
Recrehal is offline
Reply With Quote
View Public Profile Visit Recrehal's homepage!
 
When You Register, These Ads Go Away!
Old 09-29-2005, 01:50 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
What's the purpose of this piece of code? Would it not be a better idea to iterate through your long string, extract pieces of it into other smaller strings which you can then modify and recombine?
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';
Scribble Pad MOD for phpBB (aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 09-29-2005, 02:55 PM
Recrehal's Avatar
Experienced Talker

Posts: 39
Location: Aachen, Germany
I want to mark certain positions in the string and modify it later at these exact positions. The question is simply how I can work on one position, expand and thereby increasing the stringlength, while still keeping the other positions? If I simply cut the string into two pices and then join them after modifications my iterators still won't point at the right place. Again, if I modify them and insert the first substring into the large string I will lose all the other positions. So the question is how to keep these nice iterators in place or at least how to correct them.

I was thinking an iterator is something like a counter, so it would point at position 7. If I insert something into the string that is 5 chars long the 7th position won't be what I want anymore. However, if I add 5 to the 7 I should end up where I wanted to be. At least that's what I'm thinking right now but I have no clue if this is just the least bit correct.
Recrehal is offline
Reply With Quote
View Public Profile Visit Recrehal's homepage!
 
Old 10-05-2005, 12:45 PM
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
take a look at the strtok() function.

Ibbo
__________________
www.nationalclubgolfer.com www.sportspub.co.uk www.bespokecc.co.uk www.centralmarquees.co.uk
Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Reply     « Reply to C++ string iterators
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12996 seconds with 12 queries