By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,820 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

Getting an iterator to an arbitrary index of a string

P: n/a
Hey all,

Does anyone know how to get an iterator to an arbitrary location in a string (in
constant time)? This is the best I've been to do:

--- CODE ---

std::string::iterator iteratorForIndex(std::string &theString,
int position) {
return &theString[position];
}

--- CODE ---

Is there any more standard way to do it, again, in constant time?

- JFA1
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
James Aguilar wrote:
Does anyone know how to get an iterator to an arbitrary location in a string (in
constant time)?
a_string.begin() + arbitrary_location_index
This is the best I've been to do:

--- CODE ---

std::string::iterator iteratorForIndex(std::string &theString,
int position) {
return &theString[position];
}

--- CODE ---

Is there any more standard way to do it, again, in constant time?


See above.

V
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.