<?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[Vector.erase liefert unbeabsichtigte Ergebnisse]]></title><description><![CDATA[<p>Hi,<br />
ich habe einen float-Vector und möchte das größte und das kleinste element löschen,</p>
<p>Das funktioniert jedoch nicht, dass Programm löscht mir die Hälfte der Zahlen.</p>
<pre><code>for (size_t i = 0; i &lt; zufallszahlen.size(); ++i)
	{
		if (zufallszahlen[i] == min_E || max_E)
		{
			zufallszahlen.erase(zufallszahlen.begin() + i );

		}
	}
</code></pre>
<p>Das kleinste und größte Element findet es, dass haben mir meine Ausgaben bestätigt, aber es löscht wahllos Zahlen</p>
<p>Danke im Voraus für jegliche Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/334090/vector-erase-liefert-unbeabsichtigte-ergebnisse</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Apr 2026 01:02:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/334090.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 21 Aug 2015 08:44:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 08:44:30 GMT]]></title><description><![CDATA[<p>Hi,<br />
ich habe einen float-Vector und möchte das größte und das kleinste element löschen,</p>
<p>Das funktioniert jedoch nicht, dass Programm löscht mir die Hälfte der Zahlen.</p>
<pre><code>for (size_t i = 0; i &lt; zufallszahlen.size(); ++i)
	{
		if (zufallszahlen[i] == min_E || max_E)
		{
			zufallszahlen.erase(zufallszahlen.begin() + i );

		}
	}
</code></pre>
<p>Das kleinste und größte Element findet es, dass haben mir meine Ausgaben bestätigt, aber es löscht wahllos Zahlen</p>
<p>Danke im Voraus für jegliche Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2464990</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2464990</guid><dc:creator><![CDATA[C++Developer2000]]></dc:creator><pubDate>Fri, 21 Aug 2015 08:44:30 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 08:49:48 GMT]]></title><description><![CDATA[<p>Das ist immer wahr:</p>
<pre><code class="language-cpp">if (zufallszahlen[i] == min_E || max_E)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2464991</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2464991</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Fri, 21 Aug 2015 08:49:48 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 09:09:17 GMT]]></title><description><![CDATA[<p>Das liegt daran weil deine if-Bedingung als</p>
<pre><code>if ((zufallszahlen[i] == min_E) || max_E)
</code></pre>
<p>ausgewertet wird. Wenn <code>max_E</code> was anderes als 0 ist, dann ist die Bedingung immer wahr, wie manni66 schon sagte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2464996</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2464996</guid><dc:creator><![CDATA[sebi707]]></dc:creator><pubDate>Fri, 21 Aug 2015 09:09:17 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 09:20:38 GMT]]></title><description><![CDATA[<p>ok danke an euch zwei und wie umgehe ich das?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2464997</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2464997</guid><dc:creator><![CDATA[C++Developer2000]]></dc:creator><pubDate>Fri, 21 Aug 2015 09:20:38 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 09:21:19 GMT]]></title><description><![CDATA[<p>Zudem stimmt Dein Laufindex nach dem Löschen nicht mehr - Du überspringst u.U. ein Element.</p>
<p>Nimm <code>std::remove_if()</code> aus <code>&lt;algorithm&gt;</code> . <a href="https://en.wikipedia.org/wiki/Erase%E2%80%93remove_idiom" rel="nofollow">Erase-Remove-Idiom</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2464998</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2464998</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Fri, 21 Aug 2015 09:21:19 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 09:26:53 GMT]]></title><description><![CDATA[<p>C++Developer2000 schrieb:</p>
<blockquote>
<p>ok danke an euch zwei und wie umgehe ich das?</p>
</blockquote>
<p>Das Eine ist wahr, oder das Andere.<br />
Was ist das Eine?<br />
Was ist das Andere?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2465000</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465000</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Fri, 21 Aug 2015 09:26:53 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 09:46:05 GMT]]></title><description><![CDATA[<p>manni66 schrieb:</p>
<blockquote>
<p>C++Developer2000 schrieb:</p>
<blockquote>
<p>ok danke an euch zwei und wie umgehe ich das?</p>
</blockquote>
<p>Das Eine ist wahr, oder das Andere.<br />
Was ist das Eine?<br />
Was ist das Andere?</p>
</blockquote>
<p>Das eine is die schlechteste note(max_E)<br />
Das andere die bestte note (min_E)<br />
und die muss ich streichen von 20 zuvor erzeugten zufallszahlen sucht er sich max_E und min_E und soll sie streichen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2465005</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465005</guid><dc:creator><![CDATA[C++Developer2000]]></dc:creator><pubDate>Fri, 21 Aug 2015 09:46:05 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 09:51:38 GMT]]></title><description><![CDATA[<p>C++Developer2000 schrieb:</p>
<blockquote>
<p>manni66 schrieb:</p>
<blockquote>
<p>C++Developer2000 schrieb:</p>
<blockquote>
<p>ok danke an euch zwei und wie umgehe ich das?</p>
</blockquote>
<p>Das Eine ist wahr, oder das Andere.<br />
Was ist das Eine?<br />
Was ist das Andere?</p>
</blockquote>
<p>Das eine is die schlechteste note(max_E)<br />
Das andere die bestte note (min_E)<br />
und die muss ich streichen von 20 zuvor erzeugten zufallszahlen sucht er sich max_E und min_E und soll sie streichen</p>
</blockquote>
<p>Also lautet die Bedingung:<br />
Wenn 6 wahr ist oder wenn 18 wahr ist? Wirklich? Denk nach!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2465007</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465007</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Fri, 21 Aug 2015 09:51:38 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 09:54:51 GMT]]></title><description><![CDATA[<p>Ich würde es so machen:</p>
<pre><code>auto min_max = std::minmax_element(zufallszahlen.begin(), zufallszahlen.end);
zufallszahlen.erase(min_max.first);
zufallszahlen.erase(min_max.second);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2465008</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465008</guid><dc:creator><![CDATA[TNA]]></dc:creator><pubDate>Fri, 21 Aug 2015 09:54:51 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 09:56:29 GMT]]></title><description><![CDATA[<p>TNA schrieb:</p>
<blockquote>
<p>Ich würde es so machen:</p>
<pre><code>auto min_max = std::minmax_element(zufallszahlen.begin(), zufallszahlen.end);
zufallszahlen.erase(min_max.first);
zufallszahlen.erase(min_max.second);
</code></pre>
</blockquote>
<p>Da kann das erste <code>erase</code> allerdings <code>min_max.second</code> invalidieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2465010</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465010</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Fri, 21 Aug 2015 09:56:29 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 10:02:38 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">auto mm = std::minmax_element(begin(v), end(v));
auto min = *mm.first, max = *mm.second;
v.erase(std::remove_if(begin(v), end(v),
                       [min,max](int x){ return x==min || x==max; }), end(v));
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2465012</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465012</guid><dc:creator><![CDATA[lambdau-symbol]]></dc:creator><pubDate>Fri, 21 Aug 2015 10:02:38 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 10:33:30 GMT]]></title><description><![CDATA[<p>Danke @manni 66 für deinen Tipp nachzudenken</p>
<p>Lösung:</p>
<pre><code>for (size_t i = 0; i &lt; zufallszahlen.size(); ++i)
	{

		if (zufallszahlen[i] == min_E ||zufallszahlen[i]== max_E)
		{
			zufallszahlen.erase(zufallszahlen.begin() + i);

		}
	}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2465021</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465021</guid><dc:creator><![CDATA[C++Developer2000]]></dc:creator><pubDate>Fri, 21 Aug 2015 10:33:30 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 10:45:09 GMT]]></title><description><![CDATA[<p>Dein Code überspringt aber manche Zahlen, wenn diese direkt aufeinander folgen. Wenn du es weiterhin als Schleife machen möchtest dann besser so:</p>
<pre><code>auto it = zufallszahlen.begin();
while (it != zufallszahlen.end())
{
	if (*it == min_E || *it == max_E)
		it = zufallszahlen.erase(it);
	else
		++it;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2465023</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465023</guid><dc:creator><![CDATA[sebi707]]></dc:creator><pubDate>Fri, 21 Aug 2015 10:45:09 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 10:46:27 GMT]]></title><description><![CDATA[<p>Wenn du die Noten &quot;2, 2, 2, 3, 4, 4&quot; hast, willst du dann am Ende &quot;2, 2, 3, 4&quot; oder nur &quot;3&quot; haben? Weil deine Lösung macht letzteres, in der Schule ist es aber nur üblich, eine der schlechtesten Noten zu löschen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2465024</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465024</guid><dc:creator><![CDATA[vorrrausdenker]]></dc:creator><pubDate>Fri, 21 Aug 2015 10:46:27 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 10:48:16 GMT]]></title><description><![CDATA[<p>ok danke für den hinweis, schau es mir dann mal an</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2465026</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465026</guid><dc:creator><![CDATA[C++Developer2000]]></dc:creator><pubDate>Fri, 21 Aug 2015 10:48:16 GMT</pubDate></item><item><title><![CDATA[Reply to Vector.erase liefert unbeabsichtigte Ergebnisse on Fri, 21 Aug 2015 11:09:17 GMT]]></title><description><![CDATA[<p>@vorrausdenker, dessen bin ich mir bewusst und habe das im Programm auch eingebaut, nur ich hielt das für diesen Thread nicht für relevant</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2465029</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2465029</guid><dc:creator><![CDATA[C++Developer2000]]></dc:creator><pubDate>Fri, 21 Aug 2015 11:09:17 GMT</pubDate></item></channel></rss>