在struct中使用string
正常本地变量是正常的
typedef A {
string content;
} A;
A a;
a.content = "test";
这个是正常的
但是当使用c的malloc的时候,却出现的错误
A *a = (A*)malloc(sizeof(A));
a->content = "test";//错误
在c++中,应该使用
A *a = new A;
a->content = "test";//正确
在struct中使用string
正常本地变量是正常的
typedef A {
string content;
} A;
A a;
a.content = "test";
这个是正常的
但是当使用c的malloc的时候,却出现的错误
A *a = (A*)malloc(sizeof(A));
a->content = "test";//错误
在c++中,应该使用
A *a = new A;
a->content = "test";//正确