N
N
NQUARE2021-01-07 12:31:18
C++ / C#
NQUARE, 2021-01-07 12:31:18

How to iterate over all possible combinations of characters?

Can you please tell me how in C++ you can iterate through all possible combinations of characters?
There is a python code:

from itertools import product

mylist = [str(chr(i)) for i in range(33, 127)]
ofile = open('wordlist.txt', 'w')

for j in range(0, 11):
    for chars in product(mylist, repeat = j):
        ofile.write(''.join(chars) + '\n')

ofile.close()

There is a special function here, is there something similar in C++?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-01-07
@wataru

There is no finished function.
You need to either write a recursive function, or iteratively append to all array elements one element at a time from the making set. Just translate this code to c++.
The recursive function seems to be more friendly to allocations and therefore faster.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question