Print all binary of length n
            void printAllBinary(int n){
                for(int i=0; i < std::pow(2, n); i++){
                    std:string str;
                    int num = i;
                    for(int j=0; j < n; j++){
                        if(num % 2 == 0)
                            str = "0" + str;
                        else
                            str = "1" + str;
                        num = num/2;
                    }
                    std::cout<< "[" << str << "]" << std::endl;
                }
            }
            
Source Code