<?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[löschen von teilen eines vektors]]></title><description><![CDATA[<p>HALLO.</p>
<p>kann sich mal bitte jemand folgenden code anschauen? es geht darum, alle einsen aus dem vektor zu löschen, so dass am ende nur noch die 4 NULLEN übrig bleiben. leider kann ich meinen fehler nicht finden. <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>
<pre><code class="language-cpp">#include &lt;conio.h&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std; 

int main()
{
	int i;
	vector&lt;int&gt; POINT;

	POINT.push_back(1);
	POINT.push_back(1);
	POINT.push_back(0);
	POINT.push_back(0);
	POINT.push_back(0);
	POINT.push_back(0);
	POINT.push_back(1);
	POINT.push_back(1);

	for (i=0;i&lt;POINT.size();i++)
	{
		if (POINT[i]==1)
		{
			vector&lt;int&gt;::iterator platz = remove(POINT.begin()+i, POINT.end()+i,POINT[i]);
			POINT.erase(platz);
			i--;
		}
	}

	return 0;
}
</code></pre>
<p>VIELEN DANK.<br />
STICK.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/148232/löschen-von-teilen-eines-vektors</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Sep 2026 15:26:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/148232.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 24 May 2006 14:41:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to löschen von teilen eines vektors on Wed, 24 May 2006 14:41:26 GMT]]></title><description><![CDATA[<p>HALLO.</p>
<p>kann sich mal bitte jemand folgenden code anschauen? es geht darum, alle einsen aus dem vektor zu löschen, so dass am ende nur noch die 4 NULLEN übrig bleiben. leider kann ich meinen fehler nicht finden. <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>
<pre><code class="language-cpp">#include &lt;conio.h&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std; 

int main()
{
	int i;
	vector&lt;int&gt; POINT;

	POINT.push_back(1);
	POINT.push_back(1);
	POINT.push_back(0);
	POINT.push_back(0);
	POINT.push_back(0);
	POINT.push_back(0);
	POINT.push_back(1);
	POINT.push_back(1);

	for (i=0;i&lt;POINT.size();i++)
	{
		if (POINT[i]==1)
		{
			vector&lt;int&gt;::iterator platz = remove(POINT.begin()+i, POINT.end()+i,POINT[i]);
			POINT.erase(platz);
			i--;
		}
	}

	return 0;
}
</code></pre>
<p>VIELEN DANK.<br />
STICK.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1064332</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1064332</guid><dc:creator><![CDATA[stick_thai]]></dc:creator><pubDate>Wed, 24 May 2006 14:41:26 GMT</pubDate></item><item><title><![CDATA[Reply to löschen von teilen eines vektors on Wed, 24 May 2006 14:47:23 GMT]]></title><description><![CDATA[<p>Und was ist dein Fehler? Bei mir funktioniert dein Programm</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1064336</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1064336</guid><dc:creator><![CDATA[EEK]]></dc:creator><pubDate>Wed, 24 May 2006 14:47:23 GMT</pubDate></item><item><title><![CDATA[Reply to löschen von teilen eines vektors on Wed, 24 May 2006 14:52:31 GMT]]></title><description><![CDATA[<p>wie jetzt? du hast am ende nur noch 4 NULLEN stehen, und die EINSEN sind alle gelöscht? bei mir sind am ende nämlich nur noch 2 NULLEN da!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1064338</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1064338</guid><dc:creator><![CDATA[stick_thai]]></dc:creator><pubDate>Wed, 24 May 2006 14:52:31 GMT</pubDate></item><item><title><![CDATA[Reply to löschen von teilen eines vektors on Wed, 24 May 2006 14:52:57 GMT]]></title><description><![CDATA[<p>Oh, sorry da hab ich mich verschaut. Hab nicht aufgepasst das es 4 Nullen sind. Nein dann funktioniert es bei mir auch nicht, hab nur 2 Nullen übrig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1064340</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1064340</guid><dc:creator><![CDATA[EEK]]></dc:creator><pubDate>Wed, 24 May 2006 14:52:57 GMT</pubDate></item><item><title><![CDATA[Reply to löschen von teilen eines vektors on Wed, 24 May 2006 15:07:30 GMT]]></title><description><![CDATA[<p>da sind viele fehler drin...</p>
<p>wie wärs denn mit</p>
<pre><code class="language-cpp">POINT.erase(remove(POINT.begin(),POINT.end(),1),POINT.end());
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1064351</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1064351</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 24 May 2006 15:07:30 GMT</pubDate></item><item><title><![CDATA[Reply to löschen von teilen eines vektors on Wed, 24 May 2006 15:15:19 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6642">@CAMPER</a>:</p>
<p>danke, so funktioniert das schon einmal. aber nun würde ich gerne die einsen nicht alle auf einmal löschen, sondern in einer for-schleife alle nacheinander. geht das irgendwie?</p>
<p>leider hast du auch nicht gesagt, was konkret FALSCH ist. so habe ich das nächste mal auch keine ahnung, was nicht funktionieren kann <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="😉"
    /></p>
<p>DANKE.<br />
STICK.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1064354</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1064354</guid><dc:creator><![CDATA[stick_thai]]></dc:creator><pubDate>Wed, 24 May 2006 15:15:19 GMT</pubDate></item><item><title><![CDATA[Reply to löschen von teilen eines vektors on Wed, 24 May 2006 16:00:04 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">remove(POINT.begin()+i, POINT.end()+i,POINT[i])
</code></pre>
<p>Du sagst deinem Vektor hier: lösche von begin + i bis zum Ende alle Elemente, welchen den Wert POINT[i] haben. Erstens wenn du die einsen raus haben musst, muss da auch die 1 stehen. Danach bekommst du einen Iterator auf die Stelle im Feld, wo es jetzt theoretisch zu Ende ist. Praktisch wird <strong>kein Element gelöscht</strong>. Deine einsen stehen dann nur am Ende des Feldes.<br />
Schaue dir mal den remove-Algorithmus genau an.</p>
<p>Zweitens benutzt man ja remove, um gerade selber keine Schleife schreiben zu müssen. Wenn du das also &quot;per Hand&quot; machen willst, ist remove eher ungünstig.</p>
<pre><code class="language-cpp">vector&lt;int&gt;::iterator it = POINT.begin();

while(it != POINT.end())
{
    if(*it == 1)
    {
        it = POINT.erase(it);
    }
    else
    {
        ++it;
    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1064394</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1064394</guid><dc:creator><![CDATA[Pellaeon]]></dc:creator><pubDate>Wed, 24 May 2006 16:00:04 GMT</pubDate></item><item><title><![CDATA[Reply to löschen von teilen eines vektors on Wed, 24 May 2006 16:08:22 GMT]]></title><description><![CDATA[<p>@ PELLAEON:</p>
<p>danke für die antwort. meine remove-anweisung war wirklich etwas unüberlegt, will ich mal sagen. habe es inzwischen zwar selber gelöst, deine vorgeschlagene variante sieht aber durchaus eleganter aus!</p>
<p>DANKE.<br />
สทิ้ก</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1064398</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1064398</guid><dc:creator><![CDATA[stick_thai]]></dc:creator><pubDate>Wed, 24 May 2006 16:08:22 GMT</pubDate></item></channel></rss>