<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[std::map find()]]></title><description><![CDATA[<p>Hallo,</p>
<p>habe ein Problem mit find() in einer map.</p>
<p>Folgendes konstrukt:</p>
<pre><code class="language-cpp">typedef std::map&lt;wxObject*, wxString&gt; mymap;
typedef mymap::value_type Wertepaar;
mymap socket_user;
std::map&lt;wxObject*,wxString&gt;::iterator iter;
</code></pre>
<p>Nun möchte ich diese map durchsuchen.</p>
<pre><code class="language-cpp">iter = socket_user.find(UserID); //Zeile 453
if( iter != socket_user.end() ) {
     pUsers[i]-&gt;online=true;
}
else{
     pUsers[i]-&gt;online=false;
}
</code></pre>
<p>Das verursacht aber folgenden Fehler den ich nicht wirklich verstehe.</p>
<blockquote>
<p>C:\Dev-Cpp\GUI_Server\GUI_ServerFrm.cpp In member function <code>void GUI_ServerFrm::OnTimer(wxTimerEvent&amp;)': 453 C:\\Dev-Cpp\\GUI\_Server\\GUI\_ServerFrm.cpp no matching function for call to</code>std::map&lt;wxObject*, wxString, std::less&lt;wxObject*&gt;, std::allocator&lt;std::pair&lt;wxObject* const, wxString&gt; &gt; &gt;::find(wxString&amp;)'<br />
note C:\Dev-Cpp\include\c++\3.4.2\bits\stl_map.h:498 candidates are: typename std::_Rb_tree&lt;_Key, std::pair&lt;const _Key, _Tp&gt;, std::_Select1st&lt;std::pair&lt;const _Key, _Tp&gt; &gt;, _Compare, _Alloc&gt;::iterator std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::find(const _Key&amp;) [with _Key = wxObject*, _Tp = wxString, _Compare = std::less&lt;wxObject*&gt;, _Alloc = std::allocator&lt;std::pair&lt;wxObject* const, wxString&gt; &gt;]<br />
note C:\Dev-Cpp\include\c++\3.4.2\bits\stl_map.h:498 typename std::_Rb_tree&lt;_Key, std::pair&lt;const _Key, _Tp&gt;, std::_Select1st&lt;std::pair&lt;const _Key, _Tp&gt; &gt;, _Compare, _Alloc&gt;::const_iterator std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::find(const _Key&amp;) const [with _Key = wxObject*, _Tp = wxString, _Compare = std::less&lt;wxObject*&gt;, _Alloc = std::allocator&lt;std::pair&lt;wxObject* const, wxString&gt; &gt;]<br />
C:\Dev-Cpp\GUI_Server\Makefile.win [Build Error] [GUI_ServerFrm.obj] Error 1</p>
</blockquote>
<p>Hoffe mir kann jemand weiterhelfen.</p>
<p>Danke &amp; Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/179178/std-map-find</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 02:32:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/179178.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 19 Apr 2007 08:48:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::map find() on Thu, 19 Apr 2007 08:48:00 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>habe ein Problem mit find() in einer map.</p>
<p>Folgendes konstrukt:</p>
<pre><code class="language-cpp">typedef std::map&lt;wxObject*, wxString&gt; mymap;
typedef mymap::value_type Wertepaar;
mymap socket_user;
std::map&lt;wxObject*,wxString&gt;::iterator iter;
</code></pre>
<p>Nun möchte ich diese map durchsuchen.</p>
<pre><code class="language-cpp">iter = socket_user.find(UserID); //Zeile 453
if( iter != socket_user.end() ) {
     pUsers[i]-&gt;online=true;
}
else{
     pUsers[i]-&gt;online=false;
}
</code></pre>
<p>Das verursacht aber folgenden Fehler den ich nicht wirklich verstehe.</p>
<blockquote>
<p>C:\Dev-Cpp\GUI_Server\GUI_ServerFrm.cpp In member function <code>void GUI_ServerFrm::OnTimer(wxTimerEvent&amp;)': 453 C:\\Dev-Cpp\\GUI\_Server\\GUI\_ServerFrm.cpp no matching function for call to</code>std::map&lt;wxObject*, wxString, std::less&lt;wxObject*&gt;, std::allocator&lt;std::pair&lt;wxObject* const, wxString&gt; &gt; &gt;::find(wxString&amp;)'<br />
note C:\Dev-Cpp\include\c++\3.4.2\bits\stl_map.h:498 candidates are: typename std::_Rb_tree&lt;_Key, std::pair&lt;const _Key, _Tp&gt;, std::_Select1st&lt;std::pair&lt;const _Key, _Tp&gt; &gt;, _Compare, _Alloc&gt;::iterator std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::find(const _Key&amp;) [with _Key = wxObject*, _Tp = wxString, _Compare = std::less&lt;wxObject*&gt;, _Alloc = std::allocator&lt;std::pair&lt;wxObject* const, wxString&gt; &gt;]<br />
note C:\Dev-Cpp\include\c++\3.4.2\bits\stl_map.h:498 typename std::_Rb_tree&lt;_Key, std::pair&lt;const _Key, _Tp&gt;, std::_Select1st&lt;std::pair&lt;const _Key, _Tp&gt; &gt;, _Compare, _Alloc&gt;::const_iterator std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::find(const _Key&amp;) const [with _Key = wxObject*, _Tp = wxString, _Compare = std::less&lt;wxObject*&gt;, _Alloc = std::allocator&lt;std::pair&lt;wxObject* const, wxString&gt; &gt;]<br />
C:\Dev-Cpp\GUI_Server\Makefile.win [Build Error] [GUI_ServerFrm.obj] Error 1</p>
</blockquote>
<p>Hoffe mir kann jemand weiterhelfen.</p>
<p>Danke &amp; Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1269010</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1269010</guid><dc:creator><![CDATA[fub0815]]></dc:creator><pubDate>Thu, 19 Apr 2007 08:48:00 GMT</pubDate></item><item><title><![CDATA[Reply to std::map find() on Thu, 19 Apr 2007 08:56:29 GMT]]></title><description><![CDATA[<p>Die Syntax für Map ist map&lt; Key, Wert &gt;. Die Funktion find sucht nach einem Key. Scheinbar ist UserID aber vom Typ wxString, also der Wert in der Map.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1269020</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1269020</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 19 Apr 2007 08:56:29 GMT</pubDate></item><item><title><![CDATA[Reply to std::map find() on Thu, 19 Apr 2007 08:59:40 GMT]]></title><description><![CDATA[<p>Die map verwendet &lt;, um ihre Schlüssel zu vergleichen, bei deinen wxObject*s bedeutet das einen Zeiger-Vergleich. Wenn du etwas anderes haben willst, mußt du einen passenden Vergleichs-Funktor schreiben und angeben.</p>
<p>*genauer hinsieht* Aber wahrscheinlich hast du nur die Datentypen verwechselt und meintest eigentlich eine <code>map&lt;wxString,wxObject*&gt;</code> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /> (der erste Template-Parameter von map&lt;&gt; ist der Schlüssel, der zweite der Wert)</p>
<p>PS: dein if-else-Konstrukt kannst du auch kürzer schreiben:</p>
<pre><code class="language-cpp">iter = socket_user.find(UserID);
pUsers[i]-&gt;online=iter!=socket_user.end();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1269025</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1269025</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 19 Apr 2007 08:59:40 GMT</pubDate></item><item><title><![CDATA[Reply to std::map find() on Thu, 19 Apr 2007 09:07:16 GMT]]></title><description><![CDATA[<p>hmm. und nach dem wert kann ich nicht suchen? Nur nach dem Key!?</p>
<p>Dann muss ich die wohl doch tauschen...</p>
<p>Danke &amp; Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1269034</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1269034</guid><dc:creator><![CDATA[fub0815]]></dc:creator><pubDate>Thu, 19 Apr 2007 09:07:16 GMT</pubDate></item><item><title><![CDATA[Reply to std::map find() on Thu, 19 Apr 2007 09:09:57 GMT]]></title><description><![CDATA[<p>Mit der integrierten find()-Methode der map kannst du nur nach den Schlüsseln suchen. Wenn du unbedingt nach einem Wert suchen willst, kannst du die Algorithmen find() oder find_if() geeignet füttern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1269039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1269039</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 19 Apr 2007 09:09:57 GMT</pubDate></item><item><title><![CDATA[Reply to std::map find() on Thu, 19 Apr 2007 09:17:11 GMT]]></title><description><![CDATA[<blockquote>
<p>Wenn du unbedingt nach einem Wert suchen willst, kannst du die Algorithmen find() oder find_if() geeignet füttern.</p>
</blockquote>
<p>Kannst du das ein bischen genauer erklären, ich kann nämlich doch nicht so einfach tauschen und müsste nach dem wert suchen(auch der wert ist max einmal in der gesamten map).</p>
<p>meinst du das hier?<br />
<a href="http://cppreference.com/cppalgorithm/find.html" rel="nofollow">http://cppreference.com/cppalgorithm/find.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1269052</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1269052</guid><dc:creator><![CDATA[fub0815]]></dc:creator><pubDate>Thu, 19 Apr 2007 09:17:11 GMT</pubDate></item><item><title><![CDATA[Reply to std::map find() on Thu, 19 Apr 2007 09:22:04 GMT]]></title><description><![CDATA[<p>Der Algorithmus find_if() sucht in einem Iteratorbereich nach dem ersten Element, das eine vorgegebene Bedingung erfüllt. Also mußt du ihm nur die richtige Bedingung verraten:</p>
<pre><code class="language-cpp">//Suchkriterium - als Functor wegen der besseren Konfigurierbarkeit
struct finder : public unary_function&lt;Wertepaar,bool&gt;
{
  finder(const wxString&amp; name) : m_name(name) {}

  bool operator()(const Wertepaar&amp; suchwert)
  { return suchwert.second==m_name; }
private:
  const wxString&amp; m_name;
};

...
iter = find_if(socket_user.begin(),socket_user.end(),finder(UserID));
...
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1269060</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1269060</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 19 Apr 2007 09:22:04 GMT</pubDate></item><item><title><![CDATA[Reply to std::map find() on Thu, 19 Apr 2007 09:55:05 GMT]]></title><description><![CDATA[<p>Danke erstmal. Kann es sein das ich noch irgendein include fehlt? Habe noch nie etwas mit struct gemacht...oder was ist falsch!?<br />
Ich bekomme folgende Fehlermeldung</p>
<blockquote>
<p>234 C:\Dev-Cpp\GUI_Server\GUI_ServerFrm.h expected template-name before '&lt;' token<br />
234 C:\Dev-Cpp\GUI_Server\GUI_ServerFrm.h expected `{' before '&lt;' token<br />
234 C:\Dev-Cpp\GUI_Server\GUI_ServerFrm.h expected unqualified-id before '&lt;' token</p>
</blockquote>
<pre><code class="language-cpp">struct finder : public unary_function&lt;Wertepaar,bool&gt; //Zeile 234
</code></pre>
<p>wahrscheinlich eine dumme Frage, aber bin leider nicht so ein c++ pro.</p>
<p>Danke &amp; Gruß</p>
<pre><code class="language-cpp">#include &lt;functional&gt;
</code></pre>
<p>damit ändert sich auch nichts.</p>
<p>hat sich erledigt. ein std:: vor unary_function hat bei mir gefehlt!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1269093</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1269093</guid><dc:creator><![CDATA[fub0815]]></dc:creator><pubDate>Thu, 19 Apr 2007 09:55:05 GMT</pubDate></item><item><title><![CDATA[Reply to std::map find() on Thu, 19 Apr 2007 09:56:12 GMT]]></title><description><![CDATA[<p>möglicherweise fehlt auch ein std:: an der Stelle.</p>
<p>(wobei: in diesem Zusammenhang kannst du den Teil ab dem Doppelpunkt auch weglassen - ich hab's mir halt angewöhnt, Funktor-Klassen von unary- bzw. binary_function abzuleiten)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1269103</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1269103</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 19 Apr 2007 09:56:12 GMT</pubDate></item><item><title><![CDATA[Reply to std::map find() on Thu, 19 Apr 2007 10:04:44 GMT]]></title><description><![CDATA[<p>wie oben schon editiert. es hat das std:: gefehlt!<br />
Danke, funktioniert jetzt alles so wie ich mir das vorgestellt habe...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1269110</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1269110</guid><dc:creator><![CDATA[fub0815]]></dc:creator><pubDate>Thu, 19 Apr 2007 10:04:44 GMT</pubDate></item></channel></rss>