How Do I Insert Items From An Edit Control In A Double Linked List

喜你入骨 提交于 2019-12-25 06:39:03

问题


I need to insert some data from an edit control in a double linked list. How can i make this? The datatype of the edit control is CString and all are named like m_... for example m_anrede and so on...

My struct looks like this:

typedef struct adr{

    char anrede [5];
    char vorname [51];
    char nachname [51];
    char plz [8];
    char ort [60];
    char strasse [51];
    char land [24];
    char festnetz [14];
    char mobil [14];
    char mail [101];
    char geburtsdatum [11];
    char kategorie [31];
    char startnummer [5];
    char startzeit [9];
    char zeit [9];
    char rang [5];
    char fahrrad [31];
    char sponsor [31];
} adressen;


struct node{

    adressen *konto;
    struct node *prev;
    struct node *next;
};

回答1:


I'd change your data structure to make it more C++ alike:

#pragma once

class CAddress
{
public:
    CString anrede;
    CString vorname;
    CString nachname;
    CString plz;
    CString ort;
    CString strasse;
    CString land;
    CString festnetz;
    CString mobil;
    CString mail;
    CString geburtsdatum;
    CString kategorie;
    CString startnummer;
    CString startzeit;
    CString zeit;
    CString rang;
    CString fahrrad;
    CString sponsor;
};

Instead of home-grown linked list I'd use MFC-standard CList<CAddress> or even better C++ standard container (collection class): std::list<CAddress>.

So in your app window header file you'll have your list defined as class member like this:

CList<CAddress> m_AddrList;

You would need some sort of method to get user input and fill in your data structure:

void CAddressEditorDlg::FillInAddr(CAddress& addr)
{
    m_anredeEditBox.GetWindowText(addr.anrede);
    m_vornameEditBox.GetWindowText(addr.vorname);
    m_nachnameEditBox.GetWindowText(addr.nachname);
    m_plzEditBox.GetWindowText(addr.plz);
    ...
}

After that you can simply add user-configured address to your list:

void CAddressEditorDlg::OnAddAddrButton()
{
    CAddress currentAddr;
    FillInAddr(currentAddr);
    // add new addr to linked list
    m_AddrList.AddTail(currentAddr);
}

IMPORTANT: If I were you I'd dig into CList source code to see how it's implemented just for educational purposes.



来源:https://stackoverflow.com/questions/33368489/how-do-i-insert-items-from-an-edit-control-in-a-double-linked-list

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!