I'm translating a python function into a C++ function; this function uses a yield(string) statement that I don't know how to translate.
Here the whole story...I have a certain function that reads an input ASCII file filename, which contains lines of data, and puts the content of the file into an std::vector. 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 file_struct_generator, which marks as "data" the data lines and as "unused" the data lines I don't need. I need something similar to this function in C++, and in particular, I need something similar to yield(string) (pay attention, string!), but in C++ of course. Here I show you the lines of the code I need to "translate" from python to C++. How can I rewrite yield("unused") and yield("data") in C++? Or if yield is unusable in C++, can I write a similar function in C++ using something different which works as a generator? Thanks for helping me!
def file_struct_generator(filename):
if "more" in filename:
bad_line_number = 5
else:
bad_line_number = 6
yield("data")
for i in range(bad_line_number):
yield("unused")
while True:
yield("data")
EDIT: I do not use C++20, but C++11. I tried @Arthur Tacca code and it works for my purpose, thank you all.