<?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[Element eines vectors löschen]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>Ich hab folgendes Problem:</p>
<p>Ein Vektor, der Instanzen einer Klasse als Elemente hat. Ich möchte einen Vektor an einer x-Beliebigen stelle löschen.<br />
Den Index des zu löschenden Elementes hab ich mit einer &quot;while&quot;-Schleife ermittelt.</p>
<p>Folgendes hab ich inzwischen herausgefunden:<br />
1. Vektorelemente können mit: erase(iterator position); gelöscht werden.</p>
<p>2. man muss einen Iterator als Argument übergeben.</p>
<p>Meine Frage: Wie lege ich einen Iterator für mein Problem an?</p>
<p>Vielen Dank im voraus</p>
<p>gruß Arno</p>
<p>Habe ich jetzt hinbekommen:</p>
<pre><code class="language-cpp">vector&lt;MyClass&gt;::iterator pos;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/162637/element-eines-vectors-löschen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 28 Sep 2026 09:02:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/162637.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 21 Oct 2006 01:01:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Element eines vectors löschen on Sat, 21 Oct 2006 01:47:35 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>Ich hab folgendes Problem:</p>
<p>Ein Vektor, der Instanzen einer Klasse als Elemente hat. Ich möchte einen Vektor an einer x-Beliebigen stelle löschen.<br />
Den Index des zu löschenden Elementes hab ich mit einer &quot;while&quot;-Schleife ermittelt.</p>
<p>Folgendes hab ich inzwischen herausgefunden:<br />
1. Vektorelemente können mit: erase(iterator position); gelöscht werden.</p>
<p>2. man muss einen Iterator als Argument übergeben.</p>
<p>Meine Frage: Wie lege ich einen Iterator für mein Problem an?</p>
<p>Vielen Dank im voraus</p>
<p>gruß Arno</p>
<p>Habe ich jetzt hinbekommen:</p>
<pre><code class="language-cpp">vector&lt;MyClass&gt;::iterator pos;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1158511</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1158511</guid><dc:creator><![CDATA[Arno]]></dc:creator><pubDate>Sat, 21 Oct 2006 01:47:35 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Sat, 21 Oct 2006 08:02:19 GMT]]></title><description><![CDATA[<p>Hallo</p>
<blockquote>
<p>Den Index des zu löschenden Elementes hab ich mit einer &quot;while&quot;-Schleife ermittelt.</p>
</blockquote>
<p>Wenn du einen Index hast, kannst du den dazugehörigen Iterator so bestimmen</p>
<pre><code class="language-cpp">vector&lt;MyClass&gt;::iterator pos;
std::advance(pos, index);
myvector.erase(pos);
</code></pre>
<p>Allerdings wäre es in diesme Fall besser, bei der Bestimmung des zu löschenden Elements gleich mit einem Iterator anstatt des Interger-Indexes zu arbeiten.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1158530</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1158530</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Sat, 21 Oct 2006 08:02:19 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Sat, 21 Oct 2006 08:10:32 GMT]]></title><description><![CDATA[<p>Vielen Dank für den Tip.</p>
<p>Hab jetzt sämtliche Varianten durch, aber das Vektorelement wird nicht gelöscht.<br />
Kann das am Destruktor liegen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1158531</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1158531</guid><dc:creator><![CDATA[Arno]]></dc:creator><pubDate>Sat, 21 Oct 2006 08:10:32 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Sat, 21 Oct 2006 08:15:26 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">vector&lt;MyClass&gt;::iterator pos = myvector.begin();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1158532</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1158532</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Sat, 21 Oct 2006 08:15:26 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Sat, 21 Oct 2006 08:17:45 GMT]]></title><description><![CDATA[<p>Hab ich auch schon ohne Erfolg versucht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1158534</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1158534</guid><dc:creator><![CDATA[Arno]]></dc:creator><pubDate>Sat, 21 Oct 2006 08:17:45 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Sat, 21 Oct 2006 08:30:11 GMT]]></title><description><![CDATA[<p>Da ist dann doch aber etwas grundsätzlich murks, was ohne Code nicht gelöst werden kann</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1158538</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1158538</guid><dc:creator><![CDATA[Christian411]]></dc:creator><pubDate>Sat, 21 Oct 2006 08:30:11 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Sat, 21 Oct 2006 09:00:21 GMT]]></title><description><![CDATA[<p>Hab den Fehler gefunden.</p>
<p>Und zwar rufe ich .erase(pos) in der while-Schleife auf. Die Bedingung lautet &quot;i &lt; Flugzeug.size()&quot;, was natürlich nicht funktionieren kann, weil sich die grösse und die Anordnung der Elemente im Vektor ändert.</p>
<p>Sorry hab meine Ausgabe nicht genau angeschaut, sonst wäre mir das schon früher aufgefallen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1158545</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1158545</guid><dc:creator><![CDATA[Arno]]></dc:creator><pubDate>Sat, 21 Oct 2006 09:00:21 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Sat, 21 Oct 2006 09:12:04 GMT]]></title><description><![CDATA[<p>Jetzt hab ich natürlich das nächste Problem.</p>
<p>Ist es möglich mittels eines Iterators und meinen Elementfunktionen auf den Vektor zuzugreifen? Wenn ja, wie?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1158552</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1158552</guid><dc:creator><![CDATA[Arno]]></dc:creator><pubDate>Sat, 21 Oct 2006 09:12:04 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Sat, 21 Oct 2006 09:13:26 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>natürlich geht das.</p>
<pre><code class="language-cpp">vector&lt;MyClass&gt;::iterator it = ...;
it-&gt;MyMethode();
</code></pre>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1158554</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1158554</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Sat, 21 Oct 2006 09:13:26 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Sat, 21 Oct 2006 09:23:12 GMT]]></title><description><![CDATA[<p>Vielen Dank.</p>
<p>So viel zu lernen und nur so wenig Zeit, schade eigentlich.</p>
<p>Gruß Arno</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1158561</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1158561</guid><dc:creator><![CDATA[Arno]]></dc:creator><pubDate>Sat, 21 Oct 2006 09:23:12 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Sun, 22 Oct 2006 00:37:13 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile.php?mode=viewprofile&amp;u=437" rel="nofollow">Jansen</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=2" rel="nofollow">VCL/CLX (Borland C++ Builder)</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=15" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic.php?t=39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1158857</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1158857</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Sun, 22 Oct 2006 00:37:13 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Thu, 04 Oct 2007 11:29:04 GMT]]></title><description><![CDATA[<p>Ich häng mich hier mal ran.<br />
Warum geht folgendes vor den Baum:</p>
<pre><code class="language-cpp">for (MyMap::iterator it = myMap.begin(); it!=myMap.end(); it++)
{
   if (condition xyz...)
      myMap.erase(it);	
}
</code></pre>
<p>Es sieht so aus, als ob der Iteratorwert it bei erase() ungültig wird und deshalb im nächsten Schleifendurchlauf nicht inkrementiert werden kann.</p>
<p>Frage also:<br />
Wie bekomme ich einzelne Elemente in einem Durchgang aus dem Vektor bzw. Map herausgelöscht?</p>
<p>Gruß, Thomas</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1377766</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1377766</guid><dc:creator><![CDATA[Thomsn]]></dc:creator><pubDate>Thu, 04 Oct 2007 11:29:04 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Thu, 04 Oct 2007 11:34:24 GMT]]></title><description><![CDATA[<p>Das sieht nicht nur so aus, das ist auch so. Aber normalerweise gibt erase() einen Iterator auf das Element hinter der &quot;Lücke&quot; zurück, den du entgegennehmen und verwenden kannst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1377776</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1377776</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 04 Oct 2007 11:34:24 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Thu, 04 Oct 2007 11:42:55 GMT]]></title><description><![CDATA[<p>Ja, aber auch</p>
<pre><code class="language-cpp">for (MyMap::iterator it = myMap.begin(); it!=myMap.end(); it++)
{
   if (condition xyz...)
      it = myMap.erase(it);   
}
</code></pre>
<p>produziert den selben Fehler zur Laufzeit. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1377787</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1377787</guid><dc:creator><![CDATA[Thomsn]]></dc:creator><pubDate>Thu, 04 Oct 2007 11:42:55 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Thu, 04 Oct 2007 11:45:32 GMT]]></title><description><![CDATA[<p>Thomsn schrieb:</p>
<blockquote>
<p>produziert den selben Fehler zur Laufzeit. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
</blockquote>
<p>Ist vermutlich nicht derselbe - auch wenn er sich genauso äußert <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Wenn Du das letzte Element löscht gibt erase Dir den Ende-Iterator zurück. Der wird dann aufgrund der For-Schleife erneut inkrementiert. Egal wo der dann ist, er ist auf keinen Fall mehr == myMap.end(). Dadurch gelangt er ein weiteres mal in den Schleifenkörper und dann knallts gewaltig.</p>
<p>Versuche:</p>
<pre><code class="language-cpp">for (MyMap::iterator it = myMap.begin(); it!=myMap.end();)
{
   if (condition xyz...)
      it = myMap.erase(it);
   else
      ++it;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1377789</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1377789</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Thu, 04 Oct 2007 11:45:32 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Thu, 04 Oct 2007 11:54:02 GMT]]></title><description><![CDATA[<p>LordJaxom schrieb:</p>
<blockquote>
<p>Wenn Du das letzte Element löscht gibt erase Dir den Ende-Iterator zurück. Der wird dann aufgrund der For-Schleife erneut inkrementiert.</p>
</blockquote>
<p>Wäre die Rückgabe myMap.end() würde die Schleife doch ganz normal abbrechen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1377798</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1377798</guid><dc:creator><![CDATA[Thomsn]]></dc:creator><pubDate>Thu, 04 Oct 2007 11:54:02 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Thu, 04 Oct 2007 11:57:06 GMT]]></title><description><![CDATA[<p>Theoretisch ja - aber der Iterator wird am Schleifenende nochmal erhöht, BEVOR die Abbruchbedingung überprüft wird. Und was herauskommt, wenn du den end()-Iterator erhöhst, ist undefiniert (und häufig unangenehm).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1377799</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1377799</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 04 Oct 2007 11:57:06 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Thu, 04 Oct 2007 12:10:21 GMT]]></title><description><![CDATA[<p>Klar, jetzt verstehe ich. Nach dem selben Prinzip läuft auch</p>
<pre><code class="language-cpp">for (int i=0; i!=3; i++)
{
	i = 3;
}
</code></pre>
<p>ins Endlose.</p>
<p>Danke euch!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1377812</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1377812</guid><dc:creator><![CDATA[Thomsn]]></dc:creator><pubDate>Thu, 04 Oct 2007 12:10:21 GMT</pubDate></item><item><title><![CDATA[Reply to Element eines vectors löschen on Thu, 04 Oct 2007 12:23:31 GMT]]></title><description><![CDATA[<p>Das hier geht auch</p>
<pre><code class="language-cpp">for (MyMap::iterator it = myMap.begin(); it!=myMap.end();)
{
   if (condition xyz...)
      myMap.erase(it++);
   else
      ++it;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1377826</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1377826</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Thu, 04 Oct 2007 12:23:31 GMT</pubDate></item></channel></rss>