struct A
{
string st;
};
int main()
{
A *a = (A *)malloc(sizeof(A));
a->st = "print";
cout << a->st;
return 0;
}
When I use this way and it compiled successfully, but after that in runtime I got exception. So, I figure out one thing is A *a = new A;
instead of A *a = (A *)malloc(sizeof(A));
. Which way is better and without error for doing this type of things?
What should I do for runtime memory allocation?