Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement std::set or std::hash_set to filter the duplicated item in an array list?
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <p>Hence I hope to seek your advice on the following code:</p> <pre><code>#include &lt;list&gt; //--&gt; A struct to store software name and version typedef struct tagSWVERStruct{ TCHAR szSWName[255]; TCHAR szVersion[255]; }SWVERSIONSTRUCT, *LPSWVERSIONSTRUCT; //--&gt; A list of struct to store software name and version typedef std::list&lt;SWVERSIONSTRUCT&gt; 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 ********/ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload