只需运行这个程序并解释最后一行的输出为什么它打印“g”而不是“f”。在这里我的目的是知道为什么它显示以前的函数返回值?
#include <iostream>
#include <string>
std::string f() {
return "f";
}
std::string g() {
return "g";
}
int main() {
const char * s = f().c_str();
std::cout << "s = " << s << std::endl;
std::cout << "g() = " << g() << std::endl;
std::cout << "s = " << s << std::endl;
}