Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>That data structure right there should work just fine. What you should do is override the less than operator, then you could just insert them all in a map and they would be sorted. <a href="http://www.cplusplus.com/reference/stl/map/operators/" rel="nofollow">Here is more info on the comparison operators for a map</a></p> <p>Update: upon farther reflection, I would use a set, and not a map, because there is no need for a value. But here is proof it still works<br> <br>Proof this works: </p> <pre><code>#include&lt;string&gt; #include&lt;map&gt; #include&lt;stdio.h&gt; #include &lt;sstream&gt; using namespace std; struct entry { int m_id_number; string m_name1; int m_date; string m_name2; entry( int id_number, string name1, int date, string name2) : m_id_number(id_number), m_name1(name1), m_date(date), m_name2(name2) { } // Add this as a member function to `entry`. bool operator&lt;(entry const &amp;other) const { if (m_name1 &lt; other.m_name1) return true; if (m_name2 &lt; other.m_name2) return true; if (m_date &lt; other.m_date) return true; return false; } string toString() const { string returnValue; stringstream out; string dateAsString; out &lt;&lt; m_date; dateAsString = out.str(); returnValue = m_name1 + " " + m_name2 + " " + dateAsString; return returnValue; } }; int main(int argc, char *argv[]) { string names1[] = {"Dave", "John", "Mark", "Chris", "Todd"}; string names2[] = {"A", "B", "C", "D", "E", "F", "G"}; std::map&lt;entry, int&gt; mymap; for(int x = 0; x &lt; 100; ++x) { mymap.insert(pair&lt;entry, int&gt;(entry(0, names1[x%5], x, names2[x%7]), 0)); } std::map&lt;entry, int&gt;::iterator it = mymap.begin(); for(; it != mymap.end() ;++it) { printf("%s\n ", it-&gt;first.toString().c_str()); } return 0; } </code></pre>
 

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