Anagram Maker

Apr 24, 2011 at 5:44pm
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?
Apr 24, 2011 at 5:54pm
Apr 24, 2011 at 5:54pm
Apr 24, 2011 at 5:59pm
Can somebody help me out with writing the loop? It would be greatly appreicated.
Last edited on Apr 24, 2011 at 6:00pm
Apr 24, 2011 at 6:37pm
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)
Apr 24, 2011 at 10:09pm
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?
Apr 24, 2011 at 10:49pm
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.
Apr 24, 2011 at 11:26pm
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!
Apr 24, 2011 at 11:49pm
Topic archived. No new replies allowed.