<?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[Funktion mit STL vector]]></title><description><![CDATA[<p>Hallo Community!</p>
<p>Ich habe eine Klasse &quot;Zahlenliste&quot; und soll eine Funktion &quot;suche&quot; schreiben, aber ohne die STL Funktion find.<br />
Meine Funktion soll einen Iterator zurückgeben der auf die gesuchte Zahl oder hinter das letzte Element zeigt.</p>
<p>Ich weiss nicht wirklich wie ich da vorgehen muss und wie ich mich durch meine Liste &quot;bewegen&quot; kann. Was mir klar ist , dass ich mittels einer for Schleife durch meine Liste &quot;wandern&quot; muss.</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
#include&lt;vector&gt;
#include&lt;algorithm&gt;
#include&lt;cstdlib&gt;
#include&lt;cmath&gt;

using namespace std;

class Zahlenliste{
		private:
			vector&lt;int&gt; zahlen;
			vector&lt;int&gt;::iterator it;
		public:
			Zahlenliste() {}
			Zahlenliste(int n)
			{
		    	srand(time(NULL));
					for(int i=0;i&lt;n;i++)
					{
					int zahl=(int)(ceil(((double)rand()/RAND_MAX)*n));
					zahlen.push_back(zahl);
					}
			}
			friend ostream&amp; operator&lt;&lt;(ostream&amp; os,Zahlenliste&amp; a);
			it suche(int i);
};

it Zahlenliste::suche(int x)
{
for(it=zahlen.begin();it!=zahlen.end();it++)

}

ostream&amp; operator&lt;&lt;(ostream&amp; os, Zahlenliste&amp; a)
{
	int z=0;
	for(int i=0;i&lt;a.zahlen.size();i++)
		{
		os &lt;&lt; a.zahlen[i];
		if(z&lt;a.zahlen.size()-1)
		os&lt;&lt;&quot; , &quot;;
		z++;
		}
	os &lt;&lt; endl;
	return os;
}

int main()
{
Zahlenliste obj(10);
cout&lt;&lt;obj;
return 0;
}
</code></pre>
<p>Kann mir wer einen Tipp geben?</p>
<p>Lg Caro</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/260575/funktion-mit-stl-vector</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 00:32:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/260575.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 07 Feb 2010 12:03:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Funktion mit STL vector on Sun, 07 Feb 2010 12:03:31 GMT]]></title><description><![CDATA[<p>Hallo Community!</p>
<p>Ich habe eine Klasse &quot;Zahlenliste&quot; und soll eine Funktion &quot;suche&quot; schreiben, aber ohne die STL Funktion find.<br />
Meine Funktion soll einen Iterator zurückgeben der auf die gesuchte Zahl oder hinter das letzte Element zeigt.</p>
<p>Ich weiss nicht wirklich wie ich da vorgehen muss und wie ich mich durch meine Liste &quot;bewegen&quot; kann. Was mir klar ist , dass ich mittels einer for Schleife durch meine Liste &quot;wandern&quot; muss.</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
#include&lt;vector&gt;
#include&lt;algorithm&gt;
#include&lt;cstdlib&gt;
#include&lt;cmath&gt;

using namespace std;

class Zahlenliste{
		private:
			vector&lt;int&gt; zahlen;
			vector&lt;int&gt;::iterator it;
		public:
			Zahlenliste() {}
			Zahlenliste(int n)
			{
		    	srand(time(NULL));
					for(int i=0;i&lt;n;i++)
					{
					int zahl=(int)(ceil(((double)rand()/RAND_MAX)*n));
					zahlen.push_back(zahl);
					}
			}
			friend ostream&amp; operator&lt;&lt;(ostream&amp; os,Zahlenliste&amp; a);
			it suche(int i);
};

it Zahlenliste::suche(int x)
{
for(it=zahlen.begin();it!=zahlen.end();it++)

}

ostream&amp; operator&lt;&lt;(ostream&amp; os, Zahlenliste&amp; a)
{
	int z=0;
	for(int i=0;i&lt;a.zahlen.size();i++)
		{
		os &lt;&lt; a.zahlen[i];
		if(z&lt;a.zahlen.size()-1)
		os&lt;&lt;&quot; , &quot;;
		z++;
		}
	os &lt;&lt; endl;
	return os;
}

int main()
{
Zahlenliste obj(10);
cout&lt;&lt;obj;
return 0;
}
</code></pre>
<p>Kann mir wer einen Tipp geben?</p>
<p>Lg Caro</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1851790</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1851790</guid><dc:creator><![CDATA[fischldi]]></dc:creator><pubDate>Sun, 07 Feb 2010 12:03:31 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion mit STL vector on Sun, 07 Feb 2010 12:09:57 GMT]]></title><description><![CDATA[<p>Du weißt dass du &quot;wandern&quot; musst und offenbar weißt du auch wie. Du sagst du weißt aber nicht wie du dich &quot;bewegen&quot; kannst - wo ist da der Unterschied? Ich versteh dein Problem nicht ganz. Im Buch/Tutorial deiner Wahl steht doch sicherlich auch drin wie man Iteratoren dereferenziert, d.h. wie man über einen Iterator auf das entsprechende Containerelement zugreift (und es z.B. mit dem zu suchenden Element vergleicht).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1851792</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1851792</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Sun, 07 Feb 2010 12:09:57 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion mit STL vector on Sun, 07 Feb 2010 12:11:27 GMT]]></title><description><![CDATA[<p>Stimmt denn die Syntax der Funktionsdeklaration?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1851793</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1851793</guid><dc:creator><![CDATA[fischldi]]></dc:creator><pubDate>Sun, 07 Feb 2010 12:11:27 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion mit STL vector on Sun, 07 Feb 2010 12:37:48 GMT]]></title><description><![CDATA[<p>Also meine Frage ist , meine Funktion soll ja einen Iterator zurückgeben.<br />
Wenn ich meinen Iterator als private deklariere und den Funktionsrumpf so schreibe wie im Programm, dann sagt mir mein Compiler &quot;âitâ does not name a type<br />
&quot;.</p>
<p>Könnt Ihr mir einen Tipp geben wie der Rumpf aussehen muss?</p>
<pre><code class="language-cpp">it Zahlenliste::suche(int x)
{
vector&lt;int&gt;::iterator it; 
for(it=zahlen.begin();it!=zahlen.end();it++)
if(*it==x)

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1851811</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1851811</guid><dc:creator><![CDATA[fischldi]]></dc:creator><pubDate>Sun, 07 Feb 2010 12:37:48 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion mit STL vector on Sun, 07 Feb 2010 12:56:52 GMT]]></title><description><![CDATA[<p>vector&lt;int&gt;::iterator ist der Typ. Also</p>
<pre><code class="language-cpp">vector&lt;int&gt;::iterator Zahlenliste::suche(int x)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1851821</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1851821</guid><dc:creator><![CDATA[rüdiger]]></dc:creator><pubDate>Sun, 07 Feb 2010 12:56:52 GMT</pubDate></item><item><title><![CDATA[Reply to Funktion mit STL vector on Sun, 07 Feb 2010 13:02:54 GMT]]></title><description><![CDATA[<p>Vielen dank!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1851825</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1851825</guid><dc:creator><![CDATA[fischldi]]></dc:creator><pubDate>Sun, 07 Feb 2010 13:02:54 GMT</pubDate></item></channel></rss>