list用remove實現對結構體成員的刪除
阿新 • • 發佈:2019-01-09
1、使用list,首先要包含list.h標頭檔案,並使用std名稱空間
在標頭檔案中增加如下兩行說明:
#include <list>
using namespace std;
2、定義結構體,需要在結構體裡寫判斷“==”函式,如下所列,這裡重寫的"=="函式很關鍵,remove函式主要是通過判斷兩個變數是否相等來作為刪除依據的。
typedef struct CONFIG_STRU{
char stGroup[50];
char stStaffId[50];
char stPicPath[50];
bool CONFIG_STRU::operator==(const CONFIG_STRU& staff){
if (strcmp(stGroup,staff.stGroup) != 0)
{
return false;
}
if (strcmp(stStaffId,staff.stStaffId) != 0)
{
return false;
}
if (strcmp(stPicPath,staff.stPicPath) != 0)
{
return false;
}
return true;
}
}STAFF_CONFIG;
typedef list<STAFF_CONFIG> LISTSTAFFINFO;
3、定義完成後,即可以按照正常的方法使用list了。
例程函式參見:http://download.csdn.net/detail/dafenqie/9693067