[quote=引用 1 楼 zjq9931 的回复:] const string &func() { return "hello"; } 这个改成: const char *func() { return "hello"; } 应当就可以了。string &因为要经过强制类型转换。不好。 直接return 返回的是一个字符串常量。没有强制类型转换。
const string func() { return string("hello"); } int _tmain(int argc, _TCHAR* argv[]) { const string& cc = func(); printf("%s",cc.c_str()); return 0; }
const string &func() { return "hello"; } 这个改成: const char *func() { return "hello"; } 应当就可以了。string &因为要经过强制类型转换。不好。 直接return 返回的是一个字符串常量。没有强制类型转换。
64,654
社区成员
250,484
社区内容
加载中
试试用AI创作助手写篇文章吧