<?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 aus std::list enfernen]]></title><description><![CDATA[<p>hallo ich habe eine liste von Studentenobjekten und möchte nun<br />
ein beliebigen Studenten löschen :</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
using std::ostream;
using std::cout;

class Student
{
	friend ostream&amp; operator&lt;&lt; (ostream&amp;, const Student&amp;);
public:
	Student(const int&amp; ,const string&amp;, const string&amp;);
	virtual ~Student(void);
	bool operator&lt;(const Student&amp;)const;
	//bool operator==(const Student&amp;)const;
	void setNoten(const int&amp; pg, const int&amp;tk, const int&amp;ma);
	void durchschnitt();
	double getDurchschnitt()const;
	string getName()const;

private:
	int matrikelnummer;
	string name;
	string vorname;
	double tK;
	double pG;
	double mA;
	double ds;
	double med;
};
</code></pre>
<p>________________________________________________-</p>
<p>..</p>
<pre><code class="language-cpp">..
#include &lt;list&gt;
typedef std::list&lt;Student&gt; Studentlist;
void removeStud(Studentlist&amp; );

int _tmain(int argc, _TCHAR* argv[])
{
	Studentlist studentenliste;
	PGnoten pgvector;
	ifstream inFile;
	ofstream outFile;

loadList(ifstream&amp; inFile, Studentlist&amp; studentenliste); 
 std::ostream_iterator&lt;Student&gt;output(cout, &quot; &quot;);
 std::copy(studentenliste.begin(), studentenliste.end(), output);// wird schön alles angezeigt      

removeStud(Studentlist&amp;); //hier fehler//ab hier das problem....

..
}
//problem funktion!!)
void removeStud(Studentlist&amp; studentenliste)
{
	string name;
	cout&lt;&lt;&quot;Welchen Student moechten sie enfernen?:&quot;;
	cin&gt;&gt;name;
	std::list&lt;Student&gt;::iterator iter;
	for(iter=studentenliste.begin(); iter!=studentenliste.end(); ++iter)
	{
		if((*iter).getName()==name)
		{studentenliste.erase(iter); /hier runtimefehler!!
		 //--iter; //hab ich auch schon probiert geht aber nich
		}
	}
}
</code></pre>
<p>hab ich irgendein denkfehler ich dacht das geht so?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/185900/element-aus-std-list-enfernen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 06:30:26 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/185900.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 02 Jul 2007 17:15:20 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Element aus std::list enfernen on Mon, 02 Jul 2007 17:19:06 GMT]]></title><description><![CDATA[<p>hallo ich habe eine liste von Studentenobjekten und möchte nun<br />
ein beliebigen Studenten löschen :</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
using std::ostream;
using std::cout;

class Student
{
	friend ostream&amp; operator&lt;&lt; (ostream&amp;, const Student&amp;);
public:
	Student(const int&amp; ,const string&amp;, const string&amp;);
	virtual ~Student(void);
	bool operator&lt;(const Student&amp;)const;
	//bool operator==(const Student&amp;)const;
	void setNoten(const int&amp; pg, const int&amp;tk, const int&amp;ma);
	void durchschnitt();
	double getDurchschnitt()const;
	string getName()const;

private:
	int matrikelnummer;
	string name;
	string vorname;
	double tK;
	double pG;
	double mA;
	double ds;
	double med;
};
</code></pre>
<p>________________________________________________-</p>
<p>..</p>
<pre><code class="language-cpp">..
#include &lt;list&gt;
typedef std::list&lt;Student&gt; Studentlist;
void removeStud(Studentlist&amp; );

int _tmain(int argc, _TCHAR* argv[])
{
	Studentlist studentenliste;
	PGnoten pgvector;
	ifstream inFile;
	ofstream outFile;

loadList(ifstream&amp; inFile, Studentlist&amp; studentenliste); 
 std::ostream_iterator&lt;Student&gt;output(cout, &quot; &quot;);
 std::copy(studentenliste.begin(), studentenliste.end(), output);// wird schön alles angezeigt      

removeStud(Studentlist&amp;); //hier fehler//ab hier das problem....

..
}
//problem funktion!!)
void removeStud(Studentlist&amp; studentenliste)
{
	string name;
	cout&lt;&lt;&quot;Welchen Student moechten sie enfernen?:&quot;;
	cin&gt;&gt;name;
	std::list&lt;Student&gt;::iterator iter;
	for(iter=studentenliste.begin(); iter!=studentenliste.end(); ++iter)
	{
		if((*iter).getName()==name)
		{studentenliste.erase(iter); /hier runtimefehler!!
		 //--iter; //hab ich auch schon probiert geht aber nich
		}
	}
}
</code></pre>
<p>hab ich irgendein denkfehler ich dacht das geht so?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1317041</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1317041</guid><dc:creator><![CDATA[sten]]></dc:creator><pubDate>Mon, 02 Jul 2007 17:19:06 GMT</pubDate></item><item><title><![CDATA[Reply to Element aus std::list enfernen on Mon, 02 Jul 2007 17:18:41 GMT]]></title><description><![CDATA[<p>erase invalidiert den iterator. der runtimefehler tritt auf bei <code>i++</code> , weil i kein gültiger iterator mehr ist. erase gibt allerdings einen iterator auf das nächste element zurück. <code>i = --liste.erase(i)</code> wäre eine lösung;</p>
<p>oder du verwendest list::remove bzw. list::remove_if.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1317044</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1317044</guid><dc:creator><![CDATA[queer_boy]]></dc:creator><pubDate>Mon, 02 Jul 2007 17:18:41 GMT</pubDate></item><item><title><![CDATA[Reply to Element aus std::list enfernen on Mon, 02 Jul 2007 17:24:49 GMT]]></title><description><![CDATA[<p>hatte jetzt:</p>
<pre><code class="language-cpp">void removeStud(Studentlist&amp; studentenliste)
{
	string name;
	cout&lt;&lt;&quot;Welchen Student moechten sie enfernen?:&quot;;
	cin&gt;&gt;name;
	std::list&lt;Student&gt;::iterator iter;
	for(iter=studentenliste.begin(); iter!=studentenliste.end(); ++iter)
	{
		if((*iter).getName()==name)
		{
			studentenliste.remove(*iter);
		 //--iter auch schon probiert , was muss ich machen ????
		}
	}
}
</code></pre>
<p>gibt auch runtime fehler !<br />
hatte dann wieder<br />
bool Student::operator==(const Student &amp;s)const<br />
{<br />
return(s.name==name);<br />
}<br />
reingemacht aber trotzdem gehts nicht <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/1317049</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1317049</guid><dc:creator><![CDATA[sten]]></dc:creator><pubDate>Mon, 02 Jul 2007 17:24:49 GMT</pubDate></item><item><title><![CDATA[Reply to Element aus std::list enfernen on Mon, 02 Jul 2007 17:32:42 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">for(iter=studentenliste.begin(); iter!=studentenliste.end();) 
    { 
        if((*iter).getName()==name) 
        { 
            studentenliste.erase(iter++); 
        } 
        else
        {
            iter++;
        }
    }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1317056</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1317056</guid><dc:creator><![CDATA[darthdespotism]]></dc:creator><pubDate>Mon, 02 Jul 2007 17:32:42 GMT</pubDate></item><item><title><![CDATA[Reply to Element aus std::list enfernen on Mon, 02 Jul 2007 17:34:54 GMT]]></title><description><![CDATA[<p>danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1317057</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1317057</guid><dc:creator><![CDATA[sten]]></dc:creator><pubDate>Mon, 02 Jul 2007 17:34:54 GMT</pubDate></item></channel></rss>