且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 C++ 中将 const std::string 赋值给 std::string

更新时间:2023-11-12 23:32:16

您忘记了 fun 中的 return.如果您像这样更改该功能:

You've forgotten a return in fun. If you change that function like this:

std::string fun()
{
    const std::string sender = "hi";
    sender1.assign(sender);
    return sender;
}

然后代码将编译并运行良好.

then the code will compile and run fine.