How do i store each code that is being printed in a vector

#include <iostream>

using namespace std;

#include <string>

void print_all_strings(const char*,string,const int, const int);

int main()


int k = 4;

char set[] = {'0', '1', '2','3','4','5'};

//Note: this function works on all

//cases and not just the case above

int n = sizeof set;

print_all_strings(set, "", n, k);

return 0;


void print_all_strings(const char set[],string prefix,const int n, const int k)


if (k == 1)


for (int j = 0; j < n; j++)

cout << prefix + set[j] << endl;

}//Base case: k = 1, print the string k times + the remaining letter



for (int i = 0; i < n; i++)

print_all_strings(set, prefix + set[i], n, k - 1);

}//Call the function with k - 1 and the added letter

Add a std:::vector<std::string>& argument to print_all_strings. Create an empty std::vector<std::string> object in main. In print_all_strings, in addition to printing the string (cout << prefix + set[j] << endl;), push_back it onto the vector.
Thank you for your response.

However, every time I try it end up getting errors.

Do you mind adding it to the code for me.
Instead of me giving you the code, I would prefer that you post the code that gives you errors. I would rather you learn from the mistakes you made than give you a ready-made solution. I will gladly help you correct your mistakes, but I want to see your effort.

BTW, make sure you use code tags: Click the Format button that looks like "<>", and paste your code in between the code tags that are generated in the text box.

thank you. I figured it out
Registered users can post here. Sign in or register to post.