关于string的问题,动态分配一个string类型的节点,输入时有问题;谢谢
#include <iostream>using namespace std;
#include <string>
using namespace std;
struct Data
{
string str;
};
struct Node
{
Data data;
Node * NextNode;
};
bool Init_Node(Node * & e)
{
e=(Node *)malloc (sizeof( Node));
if (e==NULL)
return false;
else
return true;
};
void main()
{
Node E;
cin>>E.data.str;
cout<<E.data.str;
//这里可以///////////////////////
Node * e;
e=NULL;
if(Init_Node( e))
{
cout<<e;
cin>>e->data.str; //这里为什么会崩溃
cout<<e->data.str;
}
} 不用动态分配就用Node * e;
cin>>e->data.str;
就有问题
页:
[1]