class Same { public: void reverse(const char* str) { char* A = const_cast<char*>(str); A[0] = '1'; printf("%u ",A); printf("%u ",str); return; } }; int main() { Same re; string str = "This is nowcoder"; printf("%u ", &str); re.reverse(str.data()); cout<< str << " " << endl; return 0; }
为什么str的值被修改了呢?