Is it possible to seek a std::string::iterator safely to a given position?
std::string::iterator has a offset access operator (operator []), but it exists in the category defined by some people as undefined behavior, like it + 3.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t understand this statement. There is no such category.
std::basic_string<>::iteratoris a random access iterator and as such you can seek by just adding or subtracting an offset to / from it (which is consistent with the documentation you linked to):What’s undefined is seeking past the
end()iterator of the associated container, or before its beginning. That is, the following is undefined behaviour: