...
In this compliant solution, the pointer to exampleString's internal buffer is not generated until after the modifications modification from replace() have has completed:
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <iostream>
#include <string>
extern void g(const char *);
void f(std::string &exampleString) {
// ...
exampleString.replace(0, 2, "bb");
// ...
g(exampleString.data());
} |
...