<?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[map methode exits()?]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe so etwas implementiert:</p>
<pre><code class="language-cpp">void setValue(int key, string value){
	map.find(result)-&gt;second = value;
}
</code></pre>
<p>Das klappt wunderbar aber nur wenn ein Key der gennanten result vorhanden ist. Gibt es eventuell eine Möglichkeit erst zu überprüfen ob so ein Key in der Map ist und dies mit if-Anweisung zu splitten?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/293161/map-methode-exits</link><generator>RSS for Node</generator><lastBuildDate>Sun, 16 Aug 2026 13:08:57 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/293161.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 26 Sep 2011 15:22:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to map methode exits()? on Mon, 26 Sep 2011 15:22:50 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe so etwas implementiert:</p>
<pre><code class="language-cpp">void setValue(int key, string value){
	map.find(result)-&gt;second = value;
}
</code></pre>
<p>Das klappt wunderbar aber nur wenn ein Key der gennanten result vorhanden ist. Gibt es eventuell eine Möglichkeit erst zu überprüfen ob so ein Key in der Map ist und dies mit if-Anweisung zu splitten?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123933</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123933</guid><dc:creator><![CDATA[J.Wayne]]></dc:creator><pubDate>Mon, 26 Sep 2011 15:22:50 GMT</pubDate></item><item><title><![CDATA[Reply to map methode exits()? on Mon, 26 Sep 2011 15:27:06 GMT]]></title><description><![CDATA[<p>Find gibt doch zurück, ob das Element gefunden wurde. <a href="http://www.cplusplus.com/reference/stl/map/find/" rel="nofollow">http://www.cplusplus.com/reference/stl/map/find/</a></p>
<p>Allerdings wäre es ziemlich ineffizient, zuerst zu schauen, ob es existiert, und dann nochmal zu suchen. Einfach auf end prüfen:</p>
<pre><code class="language-cpp">void setValue(int key, string value)
{
    // falls dein compiler auto kann, einfach &quot;auto iter = ...&quot;
    std::map&lt;int, string&gt;::iterator iter = map.find(key);

    if(iter == map.end())
         // nicht gefunden
    else
        iter-&gt;second = value;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2123934</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123934</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Mon, 26 Sep 2011 15:27:06 GMT</pubDate></item><item><title><![CDATA[Reply to map methode exits()? on Mon, 26 Sep 2011 15:32:18 GMT]]></title><description><![CDATA[<p><code>std::map</code> hat die tolle Eigenschaft beim Zugriff mit dem <code>operator[]</code> immer ein Objekt zurückzugeben wird, notfalls wird eins default-konstruiert und dann zurückgegeben. Damit geht dann</p>
<pre><code class="language-cpp">void setValue( int key, const string&amp; value )
{
   mymap[key] = value;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2123936</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123936</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Mon, 26 Sep 2011 15:32:18 GMT</pubDate></item><item><title><![CDATA[Reply to map methode exits()? on Mon, 26 Sep 2011 15:53:31 GMT]]></title><description><![CDATA[<p>Danke dir PI. Genau nach so etwas einfachem hatte ich gesucht. Iteratoren sind mir nicht eingefallen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123946</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123946</guid><dc:creator><![CDATA[J.Wayne]]></dc:creator><pubDate>Mon, 26 Sep 2011 15:53:31 GMT</pubDate></item><item><title><![CDATA[Reply to map methode exits()? on Mon, 26 Sep 2011 17:07:06 GMT]]></title><description><![CDATA[<p><a href="http://www.cplusplus.com/reference/stl/map/count/" rel="nofollow">http://www.cplusplus.com/reference/stl/map/count/</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2123977</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2123977</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Mon, 26 Sep 2011 17:07:06 GMT</pubDate></item></channel></rss>