Getting an iterator to an arbitrary index of a string

J

James Aguilar

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
 
V

Victor Bazarov

James said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top