<?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[stl: Element in vector finden]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe zwei vector px1 und px2 vom Typ &quot;pixelIndex&quot;:</p>
<pre><code class="language-cpp">struct pixelIndex {
	unsigned char value;
	int x;
	int y;
};

vector&lt;pixelIndex&gt; px1;
vector&lt;pixelIndex&gt; px2;
</code></pre>
<p>Jetzt iteriere ich über px1 und möchte für jedes Element aus px1 wissen, ob es ein Element in px2 gibt, das denselben &quot;value&quot; hat.</p>
<p>Ich kenne die stl-Methode &quot;find&quot;, aber momentan sehe ich keine Anwendung, da ich ein Element suche, das ein bestimmtes Attribut hat.</p>
<p>Könnt ihr mir helfen, dieses Problem schön zu lösen (Ich könnte es auch durch zwei normale for-Schleife lösen, doch ist es mir daran gelegen, mich mehr in die STL einzuarbeitetn und schöneres C++ zu produzieren :))</p>
<p>Vielen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/313097/stl-element-in-vector-finden</link><generator>RSS for Node</generator><lastBuildDate>Sun, 02 Aug 2026 07:50:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/313097.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 21 Jan 2013 18:39:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to stl: Element in vector finden on Mon, 21 Jan 2013 18:39:38 GMT]]></title><description><![CDATA[<p>Hallo zusammen,</p>
<p>ich habe zwei vector px1 und px2 vom Typ &quot;pixelIndex&quot;:</p>
<pre><code class="language-cpp">struct pixelIndex {
	unsigned char value;
	int x;
	int y;
};

vector&lt;pixelIndex&gt; px1;
vector&lt;pixelIndex&gt; px2;
</code></pre>
<p>Jetzt iteriere ich über px1 und möchte für jedes Element aus px1 wissen, ob es ein Element in px2 gibt, das denselben &quot;value&quot; hat.</p>
<p>Ich kenne die stl-Methode &quot;find&quot;, aber momentan sehe ich keine Anwendung, da ich ein Element suche, das ein bestimmtes Attribut hat.</p>
<p>Könnt ihr mir helfen, dieses Problem schön zu lösen (Ich könnte es auch durch zwei normale for-Schleife lösen, doch ist es mir daran gelegen, mich mehr in die STL einzuarbeitetn und schöneres C++ zu produzieren :))</p>
<p>Vielen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291996</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291996</guid><dc:creator><![CDATA[freakC++]]></dc:creator><pubDate>Mon, 21 Jan 2013 18:39:38 GMT</pubDate></item><item><title><![CDATA[Reply to stl: Element in vector finden on Mon, 21 Jan 2013 18:41:20 GMT]]></title><description><![CDATA[<p>Vielleicht <a href="http://www.cplusplus.com/reference/algorithm/mismatch/" rel="nofollow">mismatch</a>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2291997</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2291997</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Mon, 21 Jan 2013 18:41:20 GMT</pubDate></item><item><title><![CDATA[Reply to stl: Element in vector finden on Mon, 21 Jan 2013 18:44:44 GMT]]></title><description><![CDATA[<p>Eher <a href="http://en.cppreference.com/w/cpp/algorithm/set_union" rel="nofollow">set_union</a>.</p>
<p>PS <a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/18082">@freakC</a>++: Zeig uns mal, wie das mit den 2 for-Schleifen aussehen würde, sonst ist das für uns ein Rätselraten, was du eigentlich willst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2292000</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292000</guid><dc:creator><![CDATA[miss matsch]]></dc:creator><pubDate>Mon, 21 Jan 2013 18:44:44 GMT</pubDate></item><item><title><![CDATA[Reply to stl: Element in vector finden on Mon, 21 Jan 2013 18:59:11 GMT]]></title><description><![CDATA[<p>Hi!</p>
<p>Zunächst muss ich eine kleine Korrektur machen, da meine struct anders aussieht. Ich habe eben einen Denkfehler gemacht. Das zu lösende Problem ist jedoch das gleiche.</p>
<pre><code class="language-cpp">struct pixelMatch {
	Feature pixel;
	Feature match;
};
</code></pre>
<p>Meine for-Schleifenlösung sieht wie folgt aus:</p>
<pre><code class="language-cpp">for(std::vector&lt;pixelMatch&gt;::iterator it1 = pxMatch1.begin(); it1 != pxMatch1.end(); ++it1) {
		for(std::vector&lt;pixelMatch&gt;::iterator it2  = pxMatch2.begin(); it2 != pxMatch2.end(); ++it2) {
			if(isEqual((*it1).pixel, (*it2).match) &amp;&amp; isEqual((*it2).pixel,(*it1).match)) {
				_matched1.push_back((*it1).pixel); //in einem anderem vector speichern
				_matched2.push_back((*it2).pixel);
			}
		}
	}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2292007</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292007</guid><dc:creator><![CDATA[freakC++]]></dc:creator><pubDate>Mon, 21 Jan 2013 18:59:11 GMT</pubDate></item><item><title><![CDATA[Reply to stl: Element in vector finden on Mon, 21 Jan 2013 19:07:16 GMT]]></title><description><![CDATA[<p>Suchst du sowas?</p>
<pre><code>#include &lt;vector&gt;
#include &lt;algorithm&gt;
#include &lt;iterator&gt;
using namespace std;

int main()
{
	int ar[] = { 1,2,3,4,5,6,7,8,9};
	vector&lt;int&gt; px1(ar,ar+9);

	int ar2[] = { 1,3,8,};
	vector&lt;int&gt; px2(ar2,ar2+3);

	vector&lt;int&gt; res;

	set_intersection( px1.begin(), px1.end(), px2.begin(), px2.end(), back_inserter(res)); // res: 1,3,8
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2292010</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292010</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Mon, 21 Jan 2013 19:07:16 GMT</pubDate></item><item><title><![CDATA[Reply to stl: Element in vector finden on Mon, 21 Jan 2013 19:11:19 GMT]]></title><description><![CDATA[<p>Muss für set_intersection der Input nicht sortiert sein?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2292011</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292011</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Mon, 21 Jan 2013 19:11:19 GMT</pubDate></item><item><title><![CDATA[Reply to stl: Element in vector finden on Mon, 21 Jan 2013 19:13:49 GMT]]></title><description><![CDATA[<p>Grütze.</p>
<p>Aber ja, muss sortiert sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2292012</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292012</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 21 Jan 2013 19:13:49 GMT</pubDate></item><item><title><![CDATA[Reply to stl: Element in vector finden on Mon, 21 Jan 2013 19:13:54 GMT]]></title><description><![CDATA[<p>dot schrieb:</p>
<blockquote>
<p>Muss für set_intersection der Input nicht sortiert sein?</p>
</blockquote>
<p>Huch, doch hast Recht. Hab ich meine Werte nun natürlich elegant gewählt. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2292013</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292013</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Mon, 21 Jan 2013 19:13:54 GMT</pubDate></item><item><title><![CDATA[Reply to stl: Element in vector finden on Mon, 21 Jan 2013 19:15:34 GMT]]></title><description><![CDATA[<p>Decimad schrieb:</p>
<blockquote>
<p>Grütze</p>
</blockquote>
<p>?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2292014</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292014</guid><dc:creator><![CDATA[out]]></dc:creator><pubDate>Mon, 21 Jan 2013 19:15:34 GMT</pubDate></item><item><title><![CDATA[Reply to stl: Element in vector finden on Mon, 21 Jan 2013 19:17:29 GMT]]></title><description><![CDATA[<p>Ich hatte von seinem Algorithmus geschrieben, er sei O(n²). Deshalb Grütze. Könnte ja auch eines davon eine Konstante sein. Ansonsten wäre sortieren zumindest theoretisch trotzdem schneller... irgendwie sowas wollte ich sagen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2292015</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292015</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 21 Jan 2013 19:17:29 GMT</pubDate></item><item><title><![CDATA[Reply to stl: Element in vector finden on Mon, 21 Jan 2013 19:24:26 GMT]]></title><description><![CDATA[<p>Decimad schrieb:</p>
<blockquote>
<p>irgendwie sowas wollte ich sagen.</p>
</blockquote>
<p>Soweit ich weiss, gibt es keinen Algorithmus in der STL, der O(n·m) oder O(n²) als Komplexität hat. Folglich gibt es für die Schleifenlösung keine direkte Alternative (ausser halt mit Lambdas verschachtelte STL-Algorithmen).</p>
<p>Ich denke aber, dass das Problem von freakC++ schneller lösbar ist. Leider fehlen immer noch ein paar Rahmenbedingungen. (Was wird mit dem Resultat gemacht? Ist pixel oder match eindeutig? Was ist Feature?)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2292022</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292022</guid><dc:creator><![CDATA[miss matsch]]></dc:creator><pubDate>Mon, 21 Jan 2013 19:24:26 GMT</pubDate></item><item><title><![CDATA[Reply to stl: Element in vector finden on Mon, 21 Jan 2013 19:28:37 GMT]]></title><description><![CDATA[<p>Nein, sowas wollte ich auch gar nicht sagen. Ich wollte ursprünglich nur behaupten dass sortieren + set_intersection schneller wäre und dazu musste ich anschließend bei aktueller Informationslage einfach &quot;Grütze&quot; sagen. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2292025</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292025</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Mon, 21 Jan 2013 19:28:37 GMT</pubDate></item><item><title><![CDATA[Reply to stl: Element in vector finden on Mon, 21 Jan 2013 19:33:27 GMT]]></title><description><![CDATA[<p>Ich würde sagen, was schneller ist, hängt davon ab, mit wievielen Elementen man es zu tun hat...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2292027</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2292027</guid><dc:creator><![CDATA[dot]]></dc:creator><pubDate>Mon, 21 Jan 2013 19:33:27 GMT</pubDate></item></channel></rss>