Given the below scenario, I'm having a list of item which might be having some duplicated item. I would like to filter the item, to print the only unique item.
Instead of duplicating a list which remove the duplicated item, I tried to insert them into std::set and std::hash_set. Nevertheless, I found no useful example to perform the operation.
Hence I hope to seek your advice on the following code:
#include <list>
//--> A struct to store software name and version
typedef struct tagSWVERStruct{
TCHAR szSWName[255];
TCHAR szVersion[255];
}SWVERSIONSTRUCT, *LPSWVERSIONSTRUCT;
//--> A list of struct to store software name and version
typedef std::list<SWVERSIONSTRUCT> LISTSWVERSION, *PLISTSWVERSION;
void main()
{
LISTSWVERSION swList;
SWVERSIONSTRUCT svSW1, svSW2, svSW3, svSW4;
CString szVersion, szName;
//Assign value
_tcscpy_s(svSW1.szSWName, _T("Adapter 1"));
_tcscpy_s(svSW2.szSWName, _T("Adapter 2"));
_tcscpy_s(svSW3.szSWName, _T("Adapter 1"));
_tcscpy_s(svSW4.szSWName, _T("Adapter 3"));
_tcscpy_s(svSW1.szVersion, _T("1.0.0"));
_tcscpy_s(svSW2.szVersion, _T("2.0.0"));
_tcscpy_s(svSW3.szVersion, _T("1.0.0"));
_tcscpy_s(svSW4.szVersion, _T("3.0.0"));
swList.push_back(svSW1);
swList.push_back(svSW2);
swList.push_back(svSW3);
swList.push_back(svSW4);
//print all the item out
LISTSWVERSION::iterator it = swList.begin();
for(; it!=swList.end(); ++it){
_tprintf(_T("%s version = %s\n"), (*it).szSWName, (*it).szVersion);
}
}
/*******
Output:
Adapter 1 version = 1.0.0
Adapter 2 version = 2.0.0
Adapter 1 version = 1.0.0
Adapter 3 version = 3.0.0
Expected Output:
Adapter 1 version = 1.0.0
Adapter 2 version = 2.0.0
Adapter 3 version = 3.0.0
********/