title: translate python function with yield(string) to C++
body: <p>I'm translating a python function into a C++ function; this function uses a <code>yield(string)</code> statement that I don't know how to translate.</p>
  <p>Here the whole story...I have a certain function that reads an input ASCII file <code>filename</code>, which contains lines of data, and puts the content of the file into an <code>std::vector</code>. When reading this input file (in another function respect with the one showed below), I need to jump a bunch of lines (5 or 6, it depends on the input file's name) and, for this purpose, I define a function, the <code>file_struct_generator</code>, which marks as &quot;data&quot; the data lines and as &quot;unused&quot; the data lines I don't need. I need something similar to this function in C++, and in particular, I need something similar to <code>yield(string)</code> (pay attention, <code>string</code>!), but in C++ of course. Here I show you the lines of the code I need to &quot;translate&quot; from python to C++. How can I rewrite <code>yield(&quot;unused&quot;)</code> and <code>yield(&quot;data&quot;)</code> in C++? Or if <code>yield</code> is unusable in C++, can I write a similar function in C++ using something different which works as a generator? Thanks for helping me!</p>
  <pre><code>def file_struct_generator(filename):
      if &quot;more&quot; in filename:
          bad_line_number = 5
      else:
          bad_line_number = 6
  
      yield(&quot;data&quot;)
      for i in range(bad_line_number):
          yield(&quot;unused&quot;)
      while True:
          yield(&quot;data&quot;)
      
  </code></pre>
  <p><strong>EDIT:</strong>
  I do not use C++20, but C++11. I tried @Arthur Tacca code and it works for my purpose, thank you all.</p>