Linux c++ 试验-7 函数里定义的string不能返回成指针


char* test()
{
	std::string aa="1213";
	return (char*)aa.c_str();
}

这种写法是错误的,正确写法应该使用new,或者传入一个缓冲区。

相关