<span style="font-size:24px;">#include<string>
using namespace std;
#include <iostream>;
#include<stdio.h>
struct temp
{
string s;
};
void main()
{
const string p="aaa";
temp *q;
//q=(struct temp*)malloc(sizeof(struct temp));
q = new temp;
q->s=p;
// printf("%s",q->s);
cout<<q->s;
}
</span>
结构体里的string 要用new分配内存 。malloc只是分配内存。 new除了分配内存还会调用构造函数的
最新推荐文章于 2022-03-12 20:03:16 发布