What is the runtime of modifying a std::string? I assume constant time or is there something more going on under the hood in the string class?
#include <string>
int main() {
std::string str = "Hello World!"
str[1] = 'a'; // <--- what is the runtime?
}
Cheers
That's right, it's constant. According to this:
Complexity
Constant.
For C++11 that is, it's unspecified for C++98, but I wouldn't assume that an implenetation with non-constant std::string::operator[]
would be commonplace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With