Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In your sample snippet your use of <code>std::includes</code> is pointless since it will use <code>operator&lt;</code> to compare your elements. Unless you are storing the <strong>same</strong> pointers in both your arrays the operation will not yield the result you are looking for.</p> <p>Comparing adresses is not the same thing as comparing the true content of your <em>c-style-strings</em>.</p> <hr> <p>You'll also have to supply <code>std::sort</code> with the neccessary comparator, preferrably <code>std::strcmp</code> (wrapped in a <em>functor</em>).</p> <p>It's currently suffering from the same problem as your use of <code>std::includes</code>, it's comparing addresses instead of the contents of your <em>c-style-strings</em>.</p> <hr> <p><em>This whole "problem" could have been avoided by using <code>std::string</code>s and <code>std::vector</code>s.</em></p> <hr> <p><strong>Example snippet</strong></p> <pre><code>#include &lt;iostream&gt; #include &lt;algorithm&gt; #include &lt;cstring&gt; typedef char gchar; gchar const * a1[5] = { "hello", "world", "stack", "overflow", "internet" }; gchar const * a2[] = { "world", "internet", "hello" }; </code></pre> <p>...</p> <pre><code>int main (int argc, char *argv[]) { auto Sorter = [](gchar const* lhs, gchar const* rhs) { return std::strcmp (lhs, rhs) &lt; 0 ? true : false; }; std::sort (a1, a1 + 5, Sorter); std::sort (a2, a2 + 3, Sorter); if (std::includes (a1, a1 + 5, a2, a2 + 3, Sorter)) { std::cerr &lt;&lt; "all elements in a2 was found in a1!\n"; } else { std::cerr &lt;&lt; "all elements in a2 wasn't found in a1!\n"; } } </code></pre> <p><strong>output</strong></p> <pre><code>all elements in a2 was found in a1! </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload