Miracle-s 发表于 2015-6-9 12:59:17

关于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;
      }
}

Miracle-s 发表于 2015-6-9 13:00:43

不用动态分配就用Node * e;
cin>>e->data.str;
就有问题
页: [1]
查看完整版本: 关于string的问题,动态分配一个string类型的节点,输入时有问题;谢谢