Consider this code--what does it display?
#include <iostream>
#include <string>
using namespace std;
int main() {
string a="hello", b=a;
a[0]='j';
cout << a << ' ' << b << endl;
return 0;
}
Now, consider this code. This code is evil, because it
casts the result of a.data() to be writable.
However, its result may be surprising. What does it display?
#include <iostream>
#include <string>
using namespace std;
int main() {
string a="hello", b=a;
char *p = (char *) a.data();
*p = 'm';
cout << a << ' ' << b << endl;
return 0;
}