<?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[Problem mit iteratoren]]></title><description><![CDATA[<p>Ich versuche gerade einen Index in einem vector zu finden. Bekomme aber nur ellenlange Fehlermeldungen</p>
<pre><code class="language-cpp">vector&lt;double&gt;::iterator it;
    // find first element in xaxis with xaxis[i] &lt; x (lower than x)
    it = lower_bound (xaxis.begin()+ int(xIndexStart), xaxis.end(), x);

    size_t l = std::distance(xaxis.begin(), it);   // index left from x
    size_t r = std::distance(xaxis.begin(), it+1); // index right from x
</code></pre>
<p>das liefert mir den Fehler</p>
<blockquote>
<p>include\math/Interpolate.h: In function 'double Interpolate(double, const std::vector&lt;double, std::allocator&lt;double&gt; &gt;&amp;, const std::vector&lt;double, std::allocator&lt;double&gt; &gt;&amp;, int&amp;)':<br />
include\math/Interpolate.h:29: warning: comparison between signed and unsigned integer expressions<br />
include\math/Interpolate.h:35: error: no match for 'operator=' in 'it = std::lower_bound [with _FIter = __gnu_cxx::__normal_iterator&lt;const double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;, _Tp = double](((const std::vector&lt;double, std::allocator&lt;double&gt; &gt;<em>)xaxis)-&gt;std::vector&lt;_Tp, _Alloc&gt;::begin [with _Tp = double, _Alloc = std::allocator&lt;double&gt;]().__gnu_cxx::__normal_iterator&lt;_Iterator, _Container&gt;::operator+ [with _Iterator = const double</em>, _Container = std::vector&lt;double, std::allocator&lt;double&gt; &gt;](((const ptrdiff_t&amp;)((const ptrdiff_t*)(&amp;((int)xIndexStart))))), ((const std::vector&lt;double, std::allocator&lt;double&gt; &gt;<em>)xaxis)-&gt;std::vector&lt;_Tp, _Alloc&gt;::end [with _Tp = double, _Alloc = std::allocator&lt;double&gt;](), ((const double&amp;)((const double</em>)(&amp; x))))'<br />
c:\qt\sdk\2010.01\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_iterator.h:669: note: candidates are: __gnu_cxx::__normal_iterator&lt;double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;&amp; __gnu_cxx::__normal_iterator&lt;double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;::operator=(const __gnu_cxx::__normal_iterator&lt;double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;&amp;)<br />
include\math/Interpolate.h:38: error: no matching function for call to 'distance(__gnu_cxx::__normal_iterator&lt;const double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;, __gnu_cxx::__normal_iterator&lt;double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;&amp;)'<br />
include\math/Interpolate.h:39: error: no matching function for call to 'distance(__gnu_cxx::__normal_iterator&lt;const double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;, __gnu_cxx::__normal_iterator&lt;double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;)'</p>
</blockquote>
<p>Sieht jemand mehr wie ich und kann mir sagen was ich falsch mache?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/272329/problem-mit-iteratoren</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 00:10:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/272329.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 15 Aug 2010 16:26:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem mit iteratoren on Sun, 15 Aug 2010 16:26:39 GMT]]></title><description><![CDATA[<p>Ich versuche gerade einen Index in einem vector zu finden. Bekomme aber nur ellenlange Fehlermeldungen</p>
<pre><code class="language-cpp">vector&lt;double&gt;::iterator it;
    // find first element in xaxis with xaxis[i] &lt; x (lower than x)
    it = lower_bound (xaxis.begin()+ int(xIndexStart), xaxis.end(), x);

    size_t l = std::distance(xaxis.begin(), it);   // index left from x
    size_t r = std::distance(xaxis.begin(), it+1); // index right from x
</code></pre>
<p>das liefert mir den Fehler</p>
<blockquote>
<p>include\math/Interpolate.h: In function 'double Interpolate(double, const std::vector&lt;double, std::allocator&lt;double&gt; &gt;&amp;, const std::vector&lt;double, std::allocator&lt;double&gt; &gt;&amp;, int&amp;)':<br />
include\math/Interpolate.h:29: warning: comparison between signed and unsigned integer expressions<br />
include\math/Interpolate.h:35: error: no match for 'operator=' in 'it = std::lower_bound [with _FIter = __gnu_cxx::__normal_iterator&lt;const double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;, _Tp = double](((const std::vector&lt;double, std::allocator&lt;double&gt; &gt;<em>)xaxis)-&gt;std::vector&lt;_Tp, _Alloc&gt;::begin [with _Tp = double, _Alloc = std::allocator&lt;double&gt;]().__gnu_cxx::__normal_iterator&lt;_Iterator, _Container&gt;::operator+ [with _Iterator = const double</em>, _Container = std::vector&lt;double, std::allocator&lt;double&gt; &gt;](((const ptrdiff_t&amp;)((const ptrdiff_t*)(&amp;((int)xIndexStart))))), ((const std::vector&lt;double, std::allocator&lt;double&gt; &gt;<em>)xaxis)-&gt;std::vector&lt;_Tp, _Alloc&gt;::end [with _Tp = double, _Alloc = std::allocator&lt;double&gt;](), ((const double&amp;)((const double</em>)(&amp; x))))'<br />
c:\qt\sdk\2010.01\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_iterator.h:669: note: candidates are: __gnu_cxx::__normal_iterator&lt;double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;&amp; __gnu_cxx::__normal_iterator&lt;double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;::operator=(const __gnu_cxx::__normal_iterator&lt;double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;&amp;)<br />
include\math/Interpolate.h:38: error: no matching function for call to 'distance(__gnu_cxx::__normal_iterator&lt;const double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;, __gnu_cxx::__normal_iterator&lt;double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;&amp;)'<br />
include\math/Interpolate.h:39: error: no matching function for call to 'distance(__gnu_cxx::__normal_iterator&lt;const double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;, __gnu_cxx::__normal_iterator&lt;double*, std::vector&lt;double, std::allocator&lt;double&gt; &gt; &gt;)'</p>
</blockquote>
<p>Sieht jemand mehr wie ich und kann mir sagen was ich falsch mache?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940303</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940303</guid><dc:creator><![CDATA[pospiech]]></dc:creator><pubDate>Sun, 15 Aug 2010 16:26:39 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit iteratoren on Sun, 15 Aug 2010 17:10:16 GMT]]></title><description><![CDATA[<p>Zeile 25 nicht im Zitat?</p>
<p>Beispiel von lower/upper bound aus <a href="http://www.cplusplus.com/reference/algorithm/lower_bound/" rel="nofollow">http://www.cplusplus.com/reference/algorithm/lower_bound/</a> auf double convertiert ... und das tut</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940308</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940308</guid><dc:creator><![CDATA[padreigh]]></dc:creator><pubDate>Sun, 15 Aug 2010 17:10:16 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit iteratoren on Sun, 15 Aug 2010 16:42:30 GMT]]></title><description><![CDATA[<p>hier der komplette Code:</p>
<pre><code class="language-cpp">#ifndef INTERPOLATE_H
#define INTERPOLATE_H

#include &lt;cassert&gt;

#include &lt;vector&gt;
using std::vector;
#include &lt;algorithm&gt;

double Interpolate(double x, const vector&lt;double&gt;&amp; xaxis, const vector&lt;double&gt; &amp; ydata, int &amp; previousXIndex = -1)
{
    size_t size = xaxis.size();

    // check if x is in valid range, otherwise return limits
    if ( x &gt;= xaxis.back() ) {
        previousXIndex = size;
        return ydata.back();
    }
    if ( x &lt;= xaxis.front() ) {
        previousXIndex = 0;
        return ydata.front();
    }

    // setup xIndexStart, according to previousXIndex,
    // if previousXIndex can be used
    size_t xIndexStart = 0;
    if (previousXIndex &gt; 0) {
        if ( previousXIndex &gt; 0 &amp;&amp; previousXIndex &lt;= size ) {
            xIndexStart = previousXIndex;
        }
    }
    vector&lt;double&gt;::iterator it;
    // find first element in xaxis with xaxis[i] &lt; x (lower than x)
    it = lower_bound (xaxis.begin()+ int(xIndexStart), xaxis.end(), x);

    size_t l = std::distance(xaxis.begin(), it);   // index left from x
    size_t r = std::distance(xaxis.begin(), it+1); // index right from x

    previousXIndex = r;  // start next search here

    if (x == xaxis[l]){
        return ydata[l];
    }

    // check ranges of l and r
    assert( !(r &lt; 0 || r &gt;= size || l &lt; 0 || l &gt;= size) );

    return ydata[l] + (ydata[r]-ydata[l]) * (x-xaxis[l]) / (xaxis[r]-xaxis[l]);
}

#endif // INTERPOLATE_H
</code></pre>
<p>Zeile 25 enthält nur ein Komentar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940310</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940310</guid><dc:creator><![CDATA[pospiech]]></dc:creator><pubDate>Sun, 15 Aug 2010 16:42:30 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit iteratoren on Sun, 15 Aug 2010 16:44:45 GMT]]></title><description><![CDATA[<p>Reduziere Dein Problem auf ein <em>vollständiges</em> aber <em>möglichst kurzes</em> Programm.</p>
<p>Beispielsweise macht folgendes Programm bei mir keine Probleme:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;ostream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

int main()
{
  static const int foo[] = {1,3,5,7,9};
  vector&lt;int&gt; vec(foo,foo+5);
  vector&lt;int&gt;::iterator it = lower_bound(vec.begin(),vec.end(),6);
  if (it!=vec.end()) {
	  cout &lt;&lt; &quot;*it --&gt; &quot; &lt;&lt; *it &lt;&lt; endl;
	  cout &lt;&lt; &quot;distance --&gt; &quot; &lt;&lt; distance(vec.begin(),it) &lt;&lt; endl;
  }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1940312</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940312</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 15 Aug 2010 16:44:45 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit iteratoren on Sun, 15 Aug 2010 16:58:08 GMT]]></title><description><![CDATA[<p>TUT:</p>
<pre><code class="language-cpp">using namespace std;

    int main () {
        double mydoub[] = {10.0,20.0,30.0,30.0,20.0,10.0,10.0,50.0,20.0};
        vector&lt;double&gt; v(mydoub,mydoub+9);           // 10.0,20.0,30.0,30.0,20.0,10.0,10.0,50.0,20.0

        vector&lt;double&gt;::iterator low,up;

        double x = 45.0;
        low=lower_bound (v.begin() + int(2), v.end(), x);
        up= upper_bound (v.begin(), v.end(), 19.0); 

        cout &lt;&lt; &quot;lower_bound at position &quot; &lt;&lt; int(low- v.begin()) &lt;&lt; endl;
        cout &lt;&lt; &quot;upper_bound at position &quot; &lt;&lt; int(up - v.begin()) &lt;&lt; endl;

        return 0;
    }
</code></pre>
<p>TUT NICHT:</p>
<pre><code class="language-cpp">using namespace std;

    int main () {
        double mydoub[] = {10.0,20.0,30.0,30.0,20.0,10.0,10.0,50.0,20.0};
        const vector&lt;double&gt; v(mydoub,mydoub+9);           // 10.0,20.0,30.0,30.0,20.0,10.0,10.0,50.0,20.0

        vector&lt;double&gt;::iterator low,up;

        double x = 45.0;
        low=lower_bound (v.begin() + int(2), v.end(), x); 
        up= upper_bound (v.begin(), v.end(), 19.0); 

        cout &lt;&lt; &quot;lower_bound at position &quot; &lt;&lt; int(low- v.begin()) &lt;&lt; endl;
        cout &lt;&lt; &quot;upper_bound at position &quot; &lt;&lt; int(up - v.begin()) &lt;&lt; endl;

        return 0;
    }
</code></pre>
<p>Finde den Unterschied <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/1940318</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940318</guid><dc:creator><![CDATA[padreigh]]></dc:creator><pubDate>Sun, 15 Aug 2010 16:58:08 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit iteratoren on Sun, 15 Aug 2010 17:00:03 GMT]]></title><description><![CDATA[<p>Wenn das const das eigentliche Problem ist, macht es dann mehr Sinn const bei der Übergabe wegzunehmen, oder jedesmal ein const_cast zu machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940319</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940319</guid><dc:creator><![CDATA[pospiech]]></dc:creator><pubDate>Sun, 15 Aug 2010 17:00:03 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit iteratoren on Sun, 15 Aug 2010 17:17:29 GMT]]></title><description><![CDATA[<p>Warum Schrauben mit dem Hammer einschlagen?<br />
Du hast nen <code>const vector&lt;double&gt;</code> dann nimm nen <code>vector&lt;double&gt;::const_iterator</code> zum iterieren <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>
<p>Edit:</p>
<p>FachmannFürAlles schrieb:</p>
<blockquote>
<p>padreigh schrieb:</p>
<blockquote>
<p>Warum Schrauben mit dem Hammer einschlagen?</p>
</blockquote>
<p>Vielleicht weil es Schlagschrauben sind? <a href="http://baustoffe.baucompany24.de/index.php/cat/c22_Schlagschrauben---Nagelduebel.html" rel="nofollow">http://baustoffe.baucompany24.de/index.php/cat/c22_Schlagschrauben---Nagelduebel.html</a></p>
</blockquote>
<p>lol ... man lernt nie aus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940322</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940322</guid><dc:creator><![CDATA[padreigh]]></dc:creator><pubDate>Sun, 15 Aug 2010 17:17:29 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit iteratoren on Sun, 15 Aug 2010 17:12:28 GMT]]></title><description><![CDATA[<p>padreigh schrieb:</p>
<blockquote>
<p>Warum Schrauben mit dem Hammer einschlagen?</p>
</blockquote>
<p>Vielleicht weil es Schlagschrauben sind? <a href="http://baustoffe.baucompany24.de/index.php/cat/c22_Schlagschrauben---Nagelduebel.html" rel="nofollow">http://baustoffe.baucompany24.de/index.php/cat/c22_Schlagschrauben---Nagelduebel.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940323</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940323</guid><dc:creator><![CDATA[FachmannFürAlles]]></dc:creator><pubDate>Sun, 15 Aug 2010 17:12:28 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit iteratoren on Sun, 15 Aug 2010 17:47:03 GMT]]></title><description><![CDATA[<p>Außerdem erwartet lower_bound, upper_bound sowie binary_search eine entsprechend sortierte Sequenz.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940335</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940335</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Sun, 15 Aug 2010 17:47:03 GMT</pubDate></item><item><title><![CDATA[Reply to Problem mit iteratoren on Sun, 15 Aug 2010 18:34:02 GMT]]></title><description><![CDATA[<p>aus</p>
<pre><code class="language-cpp">// check if x is in valid range, otherwise return limits
    if ( x &gt;= xaxis.back() ) {
        previousXIndex = size;
        return ydata.back();
</code></pre>
<p>hab ich mal vermutet das der Vektor sortiert ist ... das würde sonst keinen Sinn machen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1940349</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1940349</guid><dc:creator><![CDATA[padreigh]]></dc:creator><pubDate>Sun, 15 Aug 2010 18:34:02 GMT</pubDate></item></channel></rss>