Every combination program

Hi I did a program for all combinations of numbers and now i want to do the same one for letters, but im really struggle to do one. There is the program for combination of letters:

It's working fine, but could you tell me how to do combinations of letters the same way as this program?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
#include <iostream>
#include <algorithm>

int main(int argc, char* argv[]) {
	const unsigned short size = 5;
	int numbers[size] = {1, 2, 3, 4, 5,};

	std::sort(numbers, numbers + size);

	do {
		for(unsigned short i=0; i<size; ++i) {
			std::cout << numbers[i] << (i+1!=size?" ":"\n");
		}
	}while(std::next_permutation(numbers, numbers + size));

	std::cin.get();


	return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <algorithm>

int main(int argc, char* argv[]) {
	const unsigned short size = 5;
	char numbers[size] = { 'a', 'b', 'c', 'd', 'e'};

	std::sort(numbers, numbers + size);

	do {
		for(unsigned short i=0; i<size; ++i) {
			std::cout << numbers[i] << (i+1!=size?" ":"\n");
		}
	}while(std::next_permutation(numbers, numbers + size));

	std::cin.get();


	return 0;
}
Wow that was simple :D
Thank you
Even simpler.
1
2
3
4
5
6
  string s("abcde");

  do 
  {
    cout << s << "\n";
  } while (std::next_permutation(s.begin(), s.end()));
Topic archived. No new replies allowed.