Man kunne jo putte ordene i en vector af string's:
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
int main()
{
string::size_type ciffer[20];
bool carry[20];
vector<string >table;
cout << "Tast nogle tegn: ";
cout.flush();
string tegn;
getline(cin, tegn);
cout << "Hvor lange ord vil du have: ";
cout.flush();
unsigned int max_word_length;
cin >> max_word_length;
if(max_word_length > 20 || max_word_length == 0)
{
cout << "Du kan max lave ord med 20 tegn" << std:: endl;
return EXIT_FAILURE;
}
for(unsigned int c = 1; c <= max_word_length; c++)
{
memset(ciffer, 0, sizeof(ciffer));
memset(carry, 0, sizeof(carry));
while(!carry[c - 1])
{
string s;
for(unsigned int k = 0; k < c; k++)
{
s += tegn[ciffer[k]];
if(k == 0)
ciffer[k]++;
else if(carry[k - 1])
{
ciffer[k]++;
carry[k - 1] = false;
}
if(ciffer[k] == tegn.size())
{
carry[k] = true;
ciffer[k] = 0;
}
}
table.push_back(s);
}
}
// tree ways to print it:
for(vector<string>::iterator ix = table.begin(); ix < table.end(); ix++)
cout << *ix << endl;
for(vector<string>::size_type index = 0; index < table.size(); index++)
cout << table[index] << endl;
copy(table.begin(), table.end(), ostream_iterator<string>(cout, "\\n"));
return EXIT_SUCCESS;
}