#include <iostream> #include <string> using namespace std; const string & version3(string & s1, const string & s2); // bad design int main() { string input; string copy; string result; cout << "Enter a string: "; getline(cin, input); copy = input; cout << "Your string as entered: " << input << endl; result = version3(input, "@@@"); cout << "Your string enhanced: " << result << endl; cout << "Your original string: " << input << endl; return 0; const string & version3(string & s1, const string & s2) // bad design { string temp; temp = s2 + s1 + s2; // unsafe to return reference to local variable return temp; } 答案时程序试图引用已释放的内存 但是没看到啊,难以理解
onemoo