This question has been asked before and already has an answer. If those answers do not fully address your question, please
ask a new question
.
–
–
–
The Standard, §21.4.7.2, doesn't give any guarantees as to the complexity.
You can reasonably assume
std::basic_string::find
takes linear time in the length of the string being searched in, though, as even the naïve algorithm (check each substring for equality) has that complexity, and it's unlikely that the
std::string
constructor will build a fancy index structure to enable anything faster than that.
The complexity in terms of the pattern being searched for may reasonably vary between linear and constant, depending on the implementation.
–
–
–
–
At most, performs as many comparisons as the number of elements in the range [first,last).
http://cplusplus.com/reference/algorithm/find/
site design / logo © 2019 Stack Exchange Inc; user contributions licensed under
cc by-sa 3.0
with
attribution required
.
rev 2019.2.26.32943