Scambling up a word

How can I detect what letters there are in a word and then scambling up.
Helped me a bit but not I still need to know how to detect what letters there are in a word.
In what way do you need to 'detect' them? Do you need to check if a specific letter is present?
Well let say I got the word 'Hello'

I want to check all the letters in Hello in lower case. So h, e, l, l, o

Then I want to mix the letters up.
1
2
3
4
5
6
7
#include <cctype> // tolower()
#include <algorithm> // transform

std::string s = "Hello";

// convert to lowercase
std::transform(s.begin(), s.end(), s.begin(), tolower);


You can shuffle the letters using the link that Duoas provided. It is used in a similar way to std::transform.
Because of STL implementations, the tolower() function overloads may get in your way unless you do something like this:

1
2
3
4
5
#include <algorithm>   // transform()
#include <cctype>      // tolower()
#include <functional>  // ptr_fun<>

std::transform( s.begin(), s.end(), s.begin(), std::ptr_fun <int, int> ( std::tolower ) );

This will ensure that you get proper results across compilers.

Hope this helps.
Topic archived. No new replies allowed.