Anagram Maker

I need to make a program where a user enters a word and it lists every combination of that word in alphabetical order. The words that it lists don't have to be real. Can anyone help me out with this?
Can somebody help me out with writing the loop? It would be greatly appreicated.
Last edited on
How did i double post..?

There's an example..
If you're using an std::string,
1
2
3
4
std::string word = "banana";
std::sort( word.begin(), word.end() );
do std::cout << word << '\n';
while( std::next_permutation( word.begin(), word.end() ) );

(code not tested)
Thank you Hamsterman.

I have managed to put this code together:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

void main()
{
string word;

//Gets word from user
cout << "Please enter a word: ";
cin >> word;
cout << endl;

sort( word.begin(), word.end() );
do cout << word << '\n';
while( next_permutation( word.begin(), word.end() ) );

}


Now, I must modify this so it checks a .txt file to see if its a real word. Does anybody know how to do this?
Open the file and read the list of words into a vector or something. Instead of displaying the word inside the loop, first check the word against the dictionary listing.
I've never opened a text file before using C++. Can somebody show me how its done or is there a sample anywhere?

Thanks for your help!
Topic archived. No new replies allowed.