<?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,die in enem vector eine const Zahl findet]]></title><description><![CDATA[<p>Hallo!<br />
Leider konnte ich nicht in der c++ Reference finden, was ich wollte.<br />
Ich brauche eine funktion, die sehr aehnlich mit equal-funktion ist.<br />
Sie muss aber statt<br />
bool equal ( InputIterator1 first1, InputIterator1 last1,<br />
InputIterator2 first2 );</p>
<p>so sein</p>
<p>bool equal ( InputIterator1 first1, InputIterator1 last1,<br />
const T&amp; value );</p>
<p>Gibt es so was in c++ Bibliothek oder muss ich selbst eine schreiben?</p>
<p>Vielen Dank im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/297505/funktion-die-in-enem-vector-eine-const-zahl-findet</link><generator>RSS for Node</generator><lastBuildDate>Fri, 14 Aug 2026 10:15:31 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/297505.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 31 Dec 2011 00:32:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 00:32:53 GMT]]></title><description><![CDATA[<p>Hallo!<br />
Leider konnte ich nicht in der c++ Reference finden, was ich wollte.<br />
Ich brauche eine funktion, die sehr aehnlich mit equal-funktion ist.<br />
Sie muss aber statt<br />
bool equal ( InputIterator1 first1, InputIterator1 last1,<br />
InputIterator2 first2 );</p>
<p>so sein</p>
<p>bool equal ( InputIterator1 first1, InputIterator1 last1,<br />
const T&amp; value );</p>
<p>Gibt es so was in c++ Bibliothek oder muss ich selbst eine schreiben?</p>
<p>Vielen Dank im Voraus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162300</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162300</guid><dc:creator><![CDATA[facell]]></dc:creator><pubDate>Sat, 31 Dec 2011 00:32:53 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 00:35:15 GMT]]></title><description><![CDATA[<p>find?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162301</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162301</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 31 Dec 2011 00:35:15 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 00:40:44 GMT]]></title><description><![CDATA[<p>find hat den Typ<br />
template &lt;class InputIterator, class T&gt;<br />
InputIterator find ( InputIterator first, InputIterator last, const T&amp; value );</p>
<p>ich brauche aber genau</p>
<p>bool blabla ( InputIterator1 first1, InputIterator1 last1,<br />
const T&amp; value );</p>
<p>oder(und lieber)<br />
bool blabla ( InputIterator1 first1, InputIterator1 last1,<br />
const T&amp; value, BinaryPredicate pred );</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162302</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162302</guid><dc:creator><![CDATA[facell]]></dc:creator><pubDate>Sat, 31 Dec 2011 00:40:44 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 00:42:26 GMT]]></title><description><![CDATA[<p>Tuste den Rückgabewert von find gegen end() vergleichen, haste deinen bool.<br />
Wenn das unbedingt eine eigene Funktion sein muß, dann schreibe sie.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162303</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162303</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 31 Dec 2011 00:42:26 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 01:29:52 GMT]]></title><description><![CDATA[<p>ich hab mir sowas ausgedacht, aber es scheint etas mit dem vector falsch zu sein...<br />
Wo ist das problem?</p>
<p>Vielen Dank</p>
<pre><code>#include &lt;fstream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;cmath&gt;
#include &lt;math.h&gt;
#include &lt;map&gt;
#include &lt;iterator&gt;
#include &lt;algorithm&gt;
#include &lt;iostream&gt;
using namespace std;

struct person
{
	string name;
	int age;
	unsigned int number;

};
inline bool myequal(vector&lt;person&gt;::iterator &amp;a,vector&lt;person&gt;::iterator &amp;b,int z)
{
   while ( a!=b )
  {
     if (!((*a).age == z))
      return false;
    ++a; 
  }
  return true;
}

int main(){
	vector&lt;person&gt; piks(3);
	person otput;
	otput.name=&quot;alli&quot;;
	otput.number=10;
	otput.age=1;
	piks.push_back(otput);
	otput.age=5;
	piks.push_back(otput);
	otput.age=2;
	piks.push_back(otput);
	cout&lt;&lt;piks[1].age&lt;&lt;endl;

	if((myequal(piks.begin(),piks.end(),2))==true)  {cout&lt;&lt;&quot;hallo&quot;&lt;&lt;endl;}
	system(&quot;Pause&quot;);

}
</code></pre>
<p>output:-85....</p>
<p>Warum wird in piks den otput nicht gespeichert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162306</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162306</guid><dc:creator><![CDATA[facell]]></dc:creator><pubDate>Sat, 31 Dec 2011 01:29:52 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 01:44:02 GMT]]></title><description><![CDATA[<p>hab alles verstanden. danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162307</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162307</guid><dc:creator><![CDATA[facell]]></dc:creator><pubDate>Sat, 31 Dec 2011 01:44:02 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 01:53:52 GMT]]></title><description><![CDATA[<p>es tut mir leid, aber ich will es jetzt sortieren und jetzt geht es wieder nicht.<br />
wo ist mein fehler?-)<br />
Vieler dank im voraus.</p>
<pre><code>#include &lt;fstream&gt;
#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;cmath&gt;
#include &lt;math.h&gt;
#include &lt;map&gt;
#include &lt;iterator&gt;
#include &lt;algorithm&gt;
#include &lt;iostream&gt;
using namespace std;

struct person{
	string name;
	int age;
	unsigned int number;	

};
inline bool myequal(vector&lt;person&gt;::iterator &amp;a,vector&lt;person&gt;::iterator &amp;b,int z)
{
	cout&lt;&lt;&quot;AIIII&quot;&lt;&lt;	endl;
	bool found=false;
   while ( a!=b )
  {
     if (((*a).age == z)){
		 cout&lt;&lt;(*a).age&lt;&lt;endl;
		 found=true;}
    ++a; 
  }
  return found;
}
inline bool sortbyplace (vector&lt;person&gt;::iterator &amp;a,vector&lt;person&gt;::iterator &amp;b)
{
  return ((*a).age &lt;(*b).age);
}
int main(){

	person otput;
	vector&lt;person&gt; piks;
	vector&lt;person&gt;::iterator it;
	otput.name=&quot;alli&quot;;
	otput.number=10;
	otput.age=1;
	piks.push_back(otput);
	otput.age=5;
	piks.push_back(otput);
	otput.age=2;
	piks.push_back(otput);
	for(it=piks.begin();it!=piks.end();it++){
		cout&lt;&lt;(*it).age&lt;&lt;endl;
	}

	if((myequal(piks.begin(),piks.end(),2))==true)  {cout&lt;&lt;&quot;hallo&quot;&lt;&lt;endl;}
	stable_sort(piks.begin(),piks.end(),sortbyplace);
	/*for(it=piks.begin();it!=piks.end();it++){
		cout&lt;&lt;(*it).age&lt;&lt;endl;
	}*/

	system(&quot;Pause&quot;);

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2162308</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162308</guid><dc:creator><![CDATA[facell]]></dc:creator><pubDate>Sat, 31 Dec 2011 01:53:52 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 01:58:22 GMT]]></title><description><![CDATA[<p>geschaft.<br />
danke-))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162309</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162309</guid><dc:creator><![CDATA[facell]]></dc:creator><pubDate>Sat, 31 Dec 2011 01:58:22 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 11:01:13 GMT]]></title><description><![CDATA[<p>@facell:</p>
<p><strong>Scott Meyers Effective STL Item 43: Prefer algorithm calls to hand-written loops.</strong></p>
<p>Soll heißen, du sollst die Standard-Algorithmen nutzen wenn möglich und in deinem Beispiel ist das mehr als möglich. Das hat diverse Gründe warum man das machen sollte:</p>
<p>Scott Meyers Effective STL Item 43 Page 182 schrieb:</p>
<blockquote>
<p><strong>Efficiency</strong>: Algorithms are often more efficient than the loops programmers produce.<br />
<strong>Correctness</strong>: Writing loops is more subject to errors than is calling algorithms.<br />
<strong>Maintainability</strong>: Algorithm calls often yield code that is clearer and more straightforward than the corresponding explicit loops.</p>
</blockquote>
<p>Ich persönlich würde noch &quot;Flexibility&quot; mit aufnehmen.<br />
Dein Code ist wenig flexibel, im Gegenteil er ist beschränkt auf <code>std::vector&lt;person&gt;</code> .</p>
<p>Und das was du dort versucht hast selbst zu schreiben kann man auch ohne Probleme auf die STL adaptieren:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;iterator&gt;
#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;
#include &lt;tr1/functional&gt;

struct Person
{
    std::string name;
    int age;
    unsigned int number;

};

struct PersonYearEquals : public std::binary_function&lt;Person,int ,bool&gt;
{
	bool operator() (const Person&amp; p, const int year) const
	{
			return p.age == year;
	}
};

int main()
{
	using namespace std::tr1::placeholders;

	std::vector&lt;Person&gt; persons;
	std::vector&lt;Person&gt;::const_iterator iter;
	// fill your persons....

	// search for a person with a specific year
	iter = std::find_if(persons.begin(),persons.end(),std::tr1::bind(PersonYearEquals(), _1, 2 ));

	if(iter != persons.end())
	{
		// person was found
	}
}
</code></pre>
<p>Ich persönlich finde es immer besser wenn man vorhanden Möglichkeiten auch nutzt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162351</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162351</guid><dc:creator><![CDATA[Firefighter]]></dc:creator><pubDate>Sat, 31 Dec 2011 11:01:13 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 15:09:43 GMT]]></title><description><![CDATA[<p>binary_function ist deprecated. bind ist mittlerweile in std::</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162408</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162408</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sat, 31 Dec 2011 15:09:43 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 15:27:34 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p>binary_function ist deprecated. bind ist mittlerweile in std::</p>
</blockquote>
<p>Wenn nicht mit binary_function wie würdest du es dann machen?<br />
Das mit bind im std hat bei mir nicht kompiliert deshalb bin ich wieder auf die tr1 Variante ausgewichen.</p>
<p>Ich bin auf jeden Fall auf deinen Alternativvorschlag gespannt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162413</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162413</guid><dc:creator><![CDATA[Firefighter]]></dc:creator><pubDate>Sat, 31 Dec 2011 15:27:34 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 15:49:16 GMT]]></title><description><![CDATA[<ol>
<li>&lt;functional&gt; includen</li>
<li>einfach von gar nix ableiten, wozu auch.</li>
</ol>
]]></description><link>https://www.c-plusplus.net/forum/post/2162418</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162418</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sat, 31 Dec 2011 15:49:16 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 16:01:11 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<ol start="2">
<li>einfach von gar nix ableiten, wozu auch.</li>
</ol>
</blockquote>
<p>Hier merkt man eindeutig das du dich noch nicht mit den Effective C++ Bücher von Scott Meyers beschäftigt hast, das ableiten macht hier sehr wohl Sinn. Aber den herauszufinden, überlass ich mal dir <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2162424</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162424</guid><dc:creator><![CDATA[Firefighter]]></dc:creator><pubDate>Sat, 31 Dec 2011 16:01:11 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 16:08:13 GMT]]></title><description><![CDATA[<p>Ich habe Effective C++ gelesen und nun extra für dich nachgesehen: Funktionsobjekte werden gerade mal einen Absatz lang im Anhang angerissen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162426</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162426</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sat, 31 Dec 2011 16:08:13 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 16:08:20 GMT]]></title><description><![CDATA[<p>allows other parts of the STL implementation to ask compile-time questions of the function object.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162427</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162427</guid><dc:creator><![CDATA[unnötig]]></dc:creator><pubDate>Sat, 31 Dec 2011 16:08:20 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 16:11:17 GMT]]></title><description><![CDATA[<p>In seinem Beispiel ist das Erben hochgradig sinnlos da std::bind sowieso wieder alles platt macht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162428</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162428</guid><dc:creator><![CDATA[Ethon]]></dc:creator><pubDate>Sat, 31 Dec 2011 16:11:17 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 16:12:21 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p>Ich habe Effective C++ gelesen und nun extra für dich nachgesehen: Funktionsobjekte werden gerade mal einen Absatz lang im Anhang angerissen.</p>
</blockquote>
<p>Also ich weiß ja nicht welches Effective C++ Buch zu gelesen hast, aber ich meine das Effective STL. In diesem wird ein ganzes Kapitel lang bearbeitet.</p>
<p>Du solltest die Qualität eines Textes nicht anhand seiner Länge ausmachen, man kann auch viele Informationen in wenig Text verpacken.<br />
Dennoch empfehle ich dir, nimm dir das Kapitel aus Effective STL einmal vor und dann kannst du hier gerne nochmal Antworten.</p>
<p>Hab noch nie so viel geballte Arroganz verknüpft mit Unwissenheit auf einem Haufen gesehen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162429</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162429</guid><dc:creator><![CDATA[Firefighter]]></dc:creator><pubDate>Sat, 31 Dec 2011 16:12:21 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 16:15:38 GMT]]></title><description><![CDATA[<p>Firefighter schrieb:</p>
<blockquote>
<p>Also ich weiß ja nicht welches Effective C++ Buch zu gelesen hast, aber ich meine das Effective STL. In diesem wird ein ganzes Kapitel lang bearbeitet.</p>
</blockquote>
<p>Dann schreib das auch hin.</p>
<p>Firefighter schrieb:</p>
<blockquote>
<p>Du solltest die Qualität eines Textes nicht anhand seiner Länge ausmachen, man kann auch viele Informationen in wenig Text verpacken.</p>
</blockquote>
<p>Steht da nicht drin, Schlaumeier.</p>
<p>Firefighter schrieb:</p>
<blockquote>
<p>Dennoch empfehle ich dir, nimm dir das Kapitel aus Effective STL einmal vor</p>
</blockquote>
<p>Wenn du mir das Buch als .pdf gibts, gerne.</p>
<p>Firefighter schrieb:</p>
<blockquote>
<p>und dann kannst du hier gerne nochmal Antworten.</p>
</blockquote>
<p>Ich werde weiterhin antworten, ob's dir passt, oder nicht.</p>
<p>Firefighter schrieb:</p>
<blockquote>
<p>Hab noch nie so viel geballte Arroganz verknüpft mit Unwissenheit auf einem Haufen gesehen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
</blockquote>
<p>Kann ich so nur zurückgeben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162432</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162432</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Sat, 31 Dec 2011 16:15:38 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 16:21:08 GMT]]></title><description><![CDATA[<p>Jop Entschuldigung das ich nicht gleich das korrekt Buch erwähnt hatte, mein Fehler.</p>
<p>Worum es mir eigentlich ging ist das hier in dem Forum generell immer nach Fehlern bei Lösungen gesucht wird, anstatt selbst auch mal eine Lösung zu posten. Ich hab ja nichts gegen Konstruktive Kritik aber was von dir kam war einfach wieder nur ein Hinweisen auf eine schlechte Lösung ohne eine bessere zu präsentieren und das nervt hier gewaltig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162434</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162434</guid><dc:creator><![CDATA[Firefighter]]></dc:creator><pubDate>Sat, 31 Dec 2011 16:21:08 GMT</pubDate></item><item><title><![CDATA[Reply to funktion,die in enem vector eine const Zahl findet on Sat, 31 Dec 2011 16:26:47 GMT]]></title><description><![CDATA[<p>unnötig schrieb:</p>
<blockquote>
<p>allows other parts of the STL implementation to ask compile-time questions of the function object.</p>
</blockquote>
<p>Würde man mit C++11 und SFINAE auch all die Antworten finden können?</p>
<p>Falls ja, erwarte ich, daß die stl-Implementierung das leistet (oder bald leistet) und ich doch nicht erben muß.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2162435</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2162435</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Sat, 31 Dec 2011 16:26:47 GMT</pubDate></item></channel></rss>