Hello I've searched for iterator and reference invalidation of class string but I didn't find a result.
I have this code:
int main(){
std::string s = "const char* manipulation in C++";
auto beg = s.cbegin();
auto& r = *s.begin();
std::cout << s << std::endl;
std::cout << "*beg: " << *beg << std::endl;
std::cout << "r: " << r << std::endl;
s.replace(beg, beg + 11, "string");
std::cout << s << std::endl;
std::cout << "*beg: " << *beg << std::endl;
std::cout << "r: " << r << std::endl;
}
The output:
const char* manipulation in C++
*beg: c
r: c
string manipulation in C++
*beg: s
r: s
It looks good but I don't know whether it is undefined behavior or not. Thank you!