<?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[von std::find position zurueck bekommen statt iterator]]></title><description><![CDATA[<p>heiho</p>
<p>wie der titel schon sagt</p>
<p>ich hab nen container welchen ich durchsuchen lass,<br />
die informationen darin sind in einer bestimmten reihenfolge,<br />
ich brauch nu nicht den inhalt sondern die position in dem container als wert<br />
beispiel:</p>
<pre><code class="language-cpp">std::vector&lt;int&gt; vIntList;
vIntList.push_back(3);
vIntList.push_back(6);
vIntList.push_back(22);
vIntList.push_back(5);

std::vector&lt;int&gt;::iterator iterResult = std::find(vIntList.begin(), vIntList.end(), 22);
</code></pre>
<p>iterResult zeigt nun auf die 22, aber ich brauch die informationen das es an position 3 ist.</p>
<p>bisher mach ich das mit einem schleifen durchlauf<br />
beispiel:</p>
<pre><code class="language-cpp">std::vector&lt;int&gt; vIntList;
vIntList.push_back(3);
vIntList.push_back(6);
vIntList.push_back(22);
vIntList.push_back(5);

for(std::size_t i = 0; i &lt; vIntList.size(); ++i)
    if(vIntList[i] == 22)
        return ++i;
</code></pre>
<p>Was ich fragen wollte, gibts fuer dieses problem ein algorithmus aus der standardbibliothek ?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/197723/von-std-find-position-zurueck-bekommen-statt-iterator</link><generator>RSS for Node</generator><lastBuildDate>Thu, 01 Oct 2026 09:29:31 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/197723.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 14 Nov 2007 07:11:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to von std::find position zurueck bekommen statt iterator on Wed, 14 Nov 2007 07:11:04 GMT]]></title><description><![CDATA[<p>heiho</p>
<p>wie der titel schon sagt</p>
<p>ich hab nen container welchen ich durchsuchen lass,<br />
die informationen darin sind in einer bestimmten reihenfolge,<br />
ich brauch nu nicht den inhalt sondern die position in dem container als wert<br />
beispiel:</p>
<pre><code class="language-cpp">std::vector&lt;int&gt; vIntList;
vIntList.push_back(3);
vIntList.push_back(6);
vIntList.push_back(22);
vIntList.push_back(5);

std::vector&lt;int&gt;::iterator iterResult = std::find(vIntList.begin(), vIntList.end(), 22);
</code></pre>
<p>iterResult zeigt nun auf die 22, aber ich brauch die informationen das es an position 3 ist.</p>
<p>bisher mach ich das mit einem schleifen durchlauf<br />
beispiel:</p>
<pre><code class="language-cpp">std::vector&lt;int&gt; vIntList;
vIntList.push_back(3);
vIntList.push_back(6);
vIntList.push_back(22);
vIntList.push_back(5);

for(std::size_t i = 0; i &lt; vIntList.size(); ++i)
    if(vIntList[i] == 22)
        return ++i;
</code></pre>
<p>Was ich fragen wollte, gibts fuer dieses problem ein algorithmus aus der standardbibliothek ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1402863</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1402863</guid><dc:creator><![CDATA[EXDW]]></dc:creator><pubDate>Wed, 14 Nov 2007 07:11:04 GMT</pubDate></item><item><title><![CDATA[Reply to von std::find position zurueck bekommen statt iterator on Wed, 14 Nov 2007 07:15:41 GMT]]></title><description><![CDATA[<p>Jap:</p>
<pre><code class="language-cpp">size_t index = std::distance(vIntList.begin(), iterResult);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1402864</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1402864</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Wed, 14 Nov 2007 07:15:41 GMT</pubDate></item><item><title><![CDATA[Reply to von std::find position zurueck bekommen statt iterator on Wed, 14 Nov 2007 07:42:35 GMT]]></title><description><![CDATA[<p>also</p>
<pre><code class="language-cpp">std::vector&lt;int&gt;::iterator iterResult = std::find(vIntList.begin(), vIntList.end(), 22);
std::size_t iPos = std::distance(vIntList.begin(), iterResult) + 1;
</code></pre>
<p>?</p>
<p>Ist das performanter als ein schleifendurchlauf?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1402871</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1402871</guid><dc:creator><![CDATA[EXDW]]></dc:creator><pubDate>Wed, 14 Nov 2007 07:42:35 GMT</pubDate></item><item><title><![CDATA[Reply to von std::find position zurueck bekommen statt iterator on Wed, 14 Nov 2007 07:46:31 GMT]]></title><description><![CDATA[<p>Für vector&lt;&gt; auf jeden Fall, bei list&lt;&gt; oder set&lt;&gt; dürfte es gleich schnell sein.</p>
<p>(distance() verwendet für Random Access Iteratoren eine einfache Subtraktion, für Forward-und Bidirektionale Iteratoren eine Zählschleife)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1402875</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1402875</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 14 Nov 2007 07:46:31 GMT</pubDate></item></channel></rss>