brute force text file help

hello i am sort of new to c++ but i know about arrays and all that sort of stuff. I want to creat a program that calculate string like aaaa then aaab but for this I'm thinking i would need 4 arrays and alternate the 4th array to count up? not to sure if it would work like that just an idea. I'm not concerned with the output to the text file just yet that will be easy. do i need multiple arrays or could i use one multiple time and alternate them? thanks
A bute force approach would be:

1
2
3
4
5
6
7
8
9
10
11
const char chars[] = "abcd" ;
enum { N = 4 } ;
for( int i=0 ; i<N ; ++i )
    for( int j=0 ; j<N ; ++j )
        for( int k=0 ; k<N ; ++k )
            for( int l=0 ; l<N ; ++l )
            {
                char text[N+1] = { chars[i], chars[j], chars[k], chars[l], 0 } ;
                // use test
                std::cout << text << '\n' ;
            }

Off topic
Whats up with the 0 at the end..? Is there always a \0 at the end of a c++ string..?
Last edited on
No, there is always a zero at the end of a C style string, which is an array of char with a zero value after the last character that you care about. It's how you indicate that the string has finished. Without it, it's not a C style string - it's just an array of char
Topic archived. No new replies allowed.