title: How to approach .startswith() in C++?
body: <p>I'm new to C++, learning from books and online video tutorials. I've been trying to get the following lines of code to work, without much success. Basically, trying to find a C++ equivalent to python'a .startswith() or &quot;in&quot;.</p>
  <p>In python, what I'm trying to achieve would look like this:</p>
  <pre><code>names = [&quot;John&quot;,&quot;Mary&quot;,&quot;Joanne&quot;,&quot;David&quot;]
  for n in names:
     if n.startswith(&quot;J&quot;):
        print(n)
  </code></pre>
  <p>In javascript, the syntax would be quite similar (there are better ways of doing this, but I'm trying to keep the lines of code close to python's):</p>
  <pre><code>const names = [&quot;John&quot;,&quot;Mary&quot;,&quot;Joanne&quot;,&quot;David&quot;];
  for (let n of names) {
     if (n.startsWith(&quot;J&quot;)) {
        console.log(n);
  }
  </code></pre>
  <p>So, I assumed things would work similarly in C++, right?</p>
  <pre><code>vector &lt;string&gt; names {&quot;John&quot;,&quot;Mary&quot;,&quot;Joanne&quot;,&quot;David&quot;};
  for (auto n: names) {
     if (n[0] == &quot;J&quot;) {
        cout &lt;&lt; n &lt;&lt; endl;
  }
  </code></pre>
  <p>As I've just started learning about pointers, I might be getting confused between types / values / addresses, apologies for this.</p>
  <p>What's the best way to solve this please? Alternatively, how should I find a way to mimic what &quot;in&quot; does in python, but for C++?</p>
  <pre><code>names = [&quot;John&quot;,&quot;Mary&quot;,&quot;Joanne&quot;,&quot;David&quot;]
  for n in names:
     if &quot;J&quot; in n:
        print(n)
  </code></pre>
  <p>Thanks!</p>