title: How can I make find() work with a set of structs?
body: <p>I am using a <code>set</code> to hold structs which contain several strings. I want to be able to use the <code>find()</code> functionality of sets. However, since the set is holding structs, it doesn't work. I want <code>find()</code> to look only at one of the strings in the struct. How can this be done?</p>
  
  <p>Here's the code that I tried to use. It works fine except for the part where <code>find()</code> is used:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;set&gt;
  using namespace std;
  
  struct test
  {
      string key;
      string data;
  };
  
  bool operator&lt;(const test &amp; l, const test &amp; r)
  {
      return l.key &lt; r.key;
  }
  
  bool operator==(const test &amp; l, const test &amp; r)
  {
      return l.key == r.key;
  }
  
  set&lt;test&gt; s;
  
  int main()
  {
      test newmember;
      newmember.key = "key";
      newmember.data = "data";
      s.insert(newmember);
      s.find("key");
  }
  </code></pre>
  
  <p>Here are the error messages that I get when I try to compile it:</p>
  
  <pre><code>test.cpp:30:7: error: no matching member function for call to 'find'
      s.find("key");
      ~~^~~~
  In file included from test.cpp:3:
  In file included from /usr/include/c++/4.2.1/set:65:
  /usr/include/c++/4.2.1/bits/stl_set.h:429:7: note: candidate function not viable: no known conversion from 'const char [4]' to 'const key_type' (aka 'const test') for 1st argument
        find(const key_type&amp; __x)
        ^
  /usr/include/c++/4.2.1/bits/stl_set.h:433:7: note: candidate function not viable: no known conversion from 'const char [4]' to 'const key_type' (aka 'const test') for 1st argument
        find(const key_type&amp; __x) const
        ^
  1 error generated.
  </code></pre>