我刚刚作了一个这样的程序(不是很好,不要笑话),现在把基本思想说给你。
希望对你有所帮助//定义链表对象
CTypedPtrList<CObList,CStudent*>m_List
//CStudent是链表中存的对象(也可以是你的结构体)
//CList是链表对象//CStudent定义
class CStudent:public CObject
{
public:
CString m_Number;
CString m_Name;
public:
CStudent(){}
CStudent(LPCSTR number,LPCSTR name)
{
m_Number=number;
m_Name=name;
}
};//在链表中增加CStudent对象
void CListDlgDlg::OnButtonAdd()
{ UpdateData(true);
CStudent *student=new CStudent(m_Number,m_Name);
m_List.AddTail(student);
m_Pos=m_List.GetHeadPosition ();}//显示下一个数据
void CListDlgDlg::OnButtonNext()
{
// TODO: Add your control notification handler code here
if(m_Pos)
{
//m_List.get
CStudent *stu=m_List.GetNext (m_Pos);
m_Name=(CString)stu->m_Name ;
m_Number=stu->m_Number ;
UpdateData(false);
if(!m_Pos)
m_Pos=m_List.GetHeadPosition ();
}
}
……其它的操作就不用仔细讲了吧。
希望对你有所帮助
希望对你有所帮助//定义链表对象
CTypedPtrList<CObList,CStudent*>m_List
//CStudent是链表中存的对象(也可以是你的结构体)
//CList是链表对象//CStudent定义
class CStudent:public CObject
{
public:
CString m_Number;
CString m_Name;
public:
CStudent(){}
CStudent(LPCSTR number,LPCSTR name)
{
m_Number=number;
m_Name=name;
}
};//在链表中增加CStudent对象
void CListDlgDlg::OnButtonAdd()
{ UpdateData(true);
CStudent *student=new CStudent(m_Number,m_Name);
m_List.AddTail(student);
m_Pos=m_List.GetHeadPosition ();}//显示下一个数据
void CListDlgDlg::OnButtonNext()
{
// TODO: Add your control notification handler code here
if(m_Pos)
{
//m_List.get
CStudent *stu=m_List.GetNext (m_Pos);
m_Name=(CString)stu->m_Name ;
m_Number=stu->m_Number ;
UpdateData(false);
if(!m_Pos)
m_Pos=m_List.GetHeadPosition ();
}
}
……其它的操作就不用仔细讲了吧。
希望对你有所帮助
解决方案 »
- 对话框中的CListCtrl……不能显示
- unicode和字符串的互转...
- 用odbc打开access2000数据库
- 想写一个在论坛能自动回贴和发贴的程序
- 自己写的一个读取块的类,但是应用中却行不通,请问问题出在哪里。
- SQL Server的问题
- 各位大虾帮个忙,请问一下怎么样才能给多文档程序加开启画面?
- 模板问题?????
- 请问那位大虾有安装COM的源代码(vb)?
- XPE系统,二维码扫码枪的USB转串口后,第一次打开串口失败
- 我把TOOLBAR上的一个按钮作成CheckButton,但如何判断它的当前是Down还是Up呢?谢谢。难道要设一个变量?
- 关于mfc MDI的问题,可能比较简单给出有用方法就可以拿分哦,哈哈哈
struct tagUserData{
int UserId;//用户id号
char Name[20];//用户姓名
char IpAddress[20];//用户ip地址
char Unit[20];//用户所属单位
char Duty[20];//用户职务
int OnLine;//是否在线
//struct tagUserData * next;
};
///generate list class
CTypedPtrList<CPtrList,tagUserData*>FriendList;
/////
struct tagUserData *FriendData;
FriendData->UserId=12;
strcpy(FriendData->Name,"wwzh");
strcpy(FriendData->IpAddress ,"11.111.111.1");
strcpy(FriendData->Unit ,"office");
strcpy(FriendData->Duty ,"super");
FriendData->OnLine =1;
FriendList.AddHead (FriendData);
//////读其中的数据
struct tagUserData *UserData;
UserData=FriendList.GetHead ();
char temp[20];
strcpy(temp,UserData->IpAddress );
AfxMessageBox(temp);
我执行后,就出现问题,程序终止
没有为对象分配空间
应该
tagUserData *FriendData=new tagUserData;