<?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[cstring-array und std::lower_bound]]></title><description><![CDATA[<p>hi leute</p>
<p>hab ein cstring-array:</p>
<pre><code>const char *values[] = {&quot;value1&quot;, &quot;value2&quot;, &quot;value3&quot;, &quot;value4&quot;};
</code></pre>
<p>die strings sind sortiert. nun moechte ich testen ob ein bestimmter string in dem array vorhanden ist:</p>
<pre><code>const char *first = param_names[0];
const char *last = (param_names[0] + (count * sizeof(const char*)));
const char *needle = &quot;value2&quot;;

auto test = [](const char *lhv, const char *rhv) noexcept -&gt; bool
{
   return strcmp(lhv, rhv) &lt; 0;
};

auto it = std::lower_bound(first, last, needle, test);

bool exists = (it != last &amp;&amp; strcmp(it, needle));
</code></pre>
<p>wie mach ich das richtig ? so funktioniert das ja nicht.</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/340057/cstring-array-und-std-lower_bound</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 12:10:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/340057.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 16 Oct 2016 14:03:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to cstring-array und std::lower_bound on Sun, 16 Oct 2016 14:03:42 GMT]]></title><description><![CDATA[<p>hi leute</p>
<p>hab ein cstring-array:</p>
<pre><code>const char *values[] = {&quot;value1&quot;, &quot;value2&quot;, &quot;value3&quot;, &quot;value4&quot;};
</code></pre>
<p>die strings sind sortiert. nun moechte ich testen ob ein bestimmter string in dem array vorhanden ist:</p>
<pre><code>const char *first = param_names[0];
const char *last = (param_names[0] + (count * sizeof(const char*)));
const char *needle = &quot;value2&quot;;

auto test = [](const char *lhv, const char *rhv) noexcept -&gt; bool
{
   return strcmp(lhv, rhv) &lt; 0;
};

auto it = std::lower_bound(first, last, needle, test);

bool exists = (it != last &amp;&amp; strcmp(it, needle));
</code></pre>
<p>wie mach ich das richtig ? so funktioniert das ja nicht.</p>
<p>Meep Meep</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2511747</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2511747</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Sun, 16 Oct 2016 14:03:42 GMT</pubDate></item><item><title><![CDATA[Reply to cstring-array und std::lower_bound on Sun, 16 Oct 2016 14:07:56 GMT]]></title><description><![CDATA[<pre><code>bool exists = (it != last &amp;&amp; strcmp(it, needle));
                             ^^^^^^^^^^^^^^^^^^
</code></pre>
<p>Sollte das nicht gerade ein Vergleich auf Null sein?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2511748</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2511748</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Sun, 16 Oct 2016 14:07:56 GMT</pubDate></item><item><title><![CDATA[Reply to cstring-array und std::lower_bound on Sun, 16 Oct 2016 14:17:19 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<pre><code>bool exists = (it != last &amp;&amp; strcmp(it, needle));
                             ^^^^^^^^^^^^^^^^^^
</code></pre>
<p>Sollte das nicht gerade ein Vergleich auf Null sein?</p>
</blockquote>
<p>inwiefern auf null vergleichen ?<br />
erster vergleich sind die 2 iteratoren. wenn it == end existiert der string nicht. der 2te vergleich ist dann der string selber der von lower_bound zurueck gegeben wird. wenn it != end dann bedeutet das ja nicht das er den string gefunden hat. oder was genau meinst du ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2511750</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2511750</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Sun, 16 Oct 2016 14:17:19 GMT</pubDate></item><item><title><![CDATA[Reply to cstring-array und std::lower_bound on Sun, 16 Oct 2016 14:35:01 GMT]]></title><description><![CDATA[<p>Und was liefert strcmp im Fall gefunden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2511753</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2511753</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sun, 16 Oct 2016 14:35:01 GMT</pubDate></item><item><title><![CDATA[Reply to cstring-array und std::lower_bound on Sun, 16 Oct 2016 14:35:47 GMT]]></title><description><![CDATA[<p>so, bin einen schritt weiter. hab jetzt:</p>
<pre><code>int count = sizeof(param_names) / sizeof(char*);

   const char **first = param_names;
   const char **last = first + count;
   const char *needle = &quot;value2&quot;;

   auto test = [](const char *lhv, const char *rhv) noexcept -&gt; bool
   {
      return strcmp(lhv, rhv) &lt; 0; // (1)
   };

   auto it = std::lower_bound(first, last, t_name.c_str(), test);

   return *it != *last &amp;&amp; strcmp(needle, *it) == 0;
</code></pre>
<p>wenn ich nun in zeile (1) einen breakpoint setze, kann ich die vergleiche mitverfolgen. aber die passen nicht er geht immer richtung array ende und dann bekomm ich am ende den last pointer els ergebnis zurueck. als wenn beim vergleich in der lampda funktion was nicht stimmen wuerde</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2511754</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2511754</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Sun, 16 Oct 2016 14:35:47 GMT</pubDate></item><item><title><![CDATA[Reply to cstring-array und std::lower_bound on Sun, 16 Oct 2016 15:01:49 GMT]]></title><description><![CDATA[<p>hat sich erledigt. stimmt schon so. ich hatte bei den strings ein paat dabei die ein kleines L als anfangsbuchstaben hatten und ich dachte das waere ein großes I.<br />
war also nicht sortiert. mit richtiger sortierung funktioniert es.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2511756</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2511756</guid><dc:creator><![CDATA[Meep Meep]]></dc:creator><pubDate>Sun, 16 Oct 2016 15:01:49 GMT</pubDate></item></channel></rss>