在C++中,定义了结构体之后,怎么在函数中调用这些结构体?

2025-03-04 06:03:37
推荐回答(2个)
回答1:

我自己做了个 结构体的插入链表 你看看

#include

using namespace std;

struct node

{

 node *next;

 int data;

};

class lianbiao:public node

{

public:

 lianbiao()

 {

  head=new node[];

  head->next=0;

  head->data=0;

 }

 node *gethead()

 {

  return head;

 }

 void create_lianbiao(node *headnode);

 void show(node *headnode);

 void sethead(node *headnode)

 {

  head=headnode;

 }

private:

 node *head;

};

void lianbiao::create_lianbiao(node *headnode)

{

 headnode=new node[];

 headnode->data=0;

 headnode->next=0;

 sethead(headnode);

 int dt;

 cin>>dt;

 while(dt!=2010)

 {

  node *hd=new node[];

  hd->data=dt;

  hd->next=NULL;

  headnode->data=hd->data;

  hd->next=headnode->next;

  headnode->next=hd;

  cin>>dt; 

 }

}

void lianbiao::show(node *headnode)

{

 headnode=headnode->next;

 while(headnode->next!=NULL)

 {

  cout<data<<" ";

  headnode=headnode->next;

 }

 cout<data;

}

int main()

{

 lianbiao lb;

 lb.create_lianbiao(lb.gethead());

 lb.show(lb.gethead());

 return 0;

}

回答2:

C++控制台输出例子:
#include
#include
//定义结构体
struct point
{
//包含两个变量成员
int x;
int y;
};
using namespace std;
int main(int argc, char *argv[])
{
struct point pt;
pt.x=1;
pt.y=2;
cout< return EXIT_SUCCESS;
}