如何结束并储存链表?

提示用户按一定格式以及需要输入各项信息,包括姓名,编号,联系方式,身份证号,出入校时间,通过链表录入系统,以'#’作为输入结束。用C++如何实现?

#include <iostream>
using namespace std;
typedef struct _times
{
    int hour;
    int mins;
    int sec;
}times;

typedef struct _student
{
    char name[20];
    int id;
    char tel[15];
    char code[20];
    times inTime;
    times outTime;
}student;

typedef struct _node
{
    student stu;
    struct _node *next;
}node;

void createlink(node *head)
{
    node *p = head;
    char sel;
    do
    {
        node *q = new node;
        cout<<"请输入姓名:";
        cin>>q->stu.name;
        cout<<"请输入编号:";
        cin>>q->stu.id;
        cout<<"请输入联系方式:";
        cin>>q->stu.tel;
        cout<<"请输入身份证号:";
        cin>>q->stu.code;
        cout<<"请输入入校时间:";
        cin>>q->stu.inTime.hour>>q->stu.inTime.mins>>q->stu.inTime.sec;
        cout<<"请输入离校时间:";
        cin>>q->stu.outTime.hour>>q->stu.outTime.mins>>q->stu.outTime.sec;
        q->next = NULL;
        p->next = q;
        p = q;
        cout<<"继续添加请请输入#号:";
        cin>>sel;
    }while(sel != '#');
}

int main()
{
    node *head = new node;
    head->next = NULL;
    createlink(head);
    return 0;
}

C++之特定人数的个人信息输入和输出
如有帮助,望采纳
https://blog.csdn.net/t211891851/article/details/72884608

C++代码如下:


#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

struct Node
{
    string name;
    int id;
    string contact;
    string id_number;
    string time_in;
    string time_out;
    Node *next;
};

void addNode(Node *&head, Node *newNode)
{
    if (head == NULL)
    {
        head = newNode;
    }
    else
    {
        Node *temp = head;
        while (temp->next != NULL)
        {
            temp = temp->next;
        }
        temp->next = newNode;
    }
}

int main()
{
    Node *head = NULL;

    cout << "请输入各项信息,以#结束。" << endl;

    while (true)
    {
        Node *newNode = new Node;
        cout << "姓名:";
        cin >> newNode->name;
        if (newNode->name == "#")
        {
            break;
        }
        cout << "编号:";
        cin >> newNode->id;
        cout << "联系方式:";
        cin >> newNode->contact;
        cout << "身份证号:";
        cin >> newNode->id_number;
        cout << "出入校时间:";
        cin >> newNode->time_in;
        cin >> newNode->time_out;

        addNode(head, newNode);
    }

    // 遍历链表,输出信息
    Node *temp = head;
    while (temp != NULL)
    {
        cout << temp->name << " " << temp->id << " " << temp->contact << " " << temp->id_number << " " << temp->time_in << " " << temp->time_out << endl;
        temp = temp->next;
    }

    return 0;
}