C
Falls es irgendjemand interessiert noch zusammengefasst eine Version, welche bei mir zumindest in VS2008 lauffähig ist (weil ich das kleine Progrämmchen von Werner eigtl. ziemlich cool finde). Vielleicht interessierts ja jemand
#include <algorithm> // transform
#include <ctime> // time
#include <cstdlib> // (s)rand
#include <iostream>
#include <locale> // ctype
#include <string>
struct LowerComp {
char& c;
const std::ctype<char>& ct;
LowerComp(char& lc, const std::ctype<char>& lct) : c(lc), ct(lct) {}
char operator()( char w, char r ) { return ct.tolower( c ) == ct.tolower( w ) ? w : r; }
};
int main()
{
using namespace std;
string words[] = {
"Yachtclubbesitzer",
"Bettelmoench",
"HangMan",
"Motoraufhaengung",
"Hundefaenger",
"Koelnisch-Wasser",
"Neuschwanstein",
"Regenbogenforelle",
"USB-Stick",
"Grobmotoriker"
};
srand( (unsigned int) time(0) );
const string& word = words[rand() % sizeof(words)/sizeof(*words)];
cout << "Bitte Buchstaben eingeben, un das Wort zu raten" << endl;
const ctype< char >& ct = use_facet< ctype< char > >( locale() );
string result( word.size(), '-' );
for( char c; result != word && cin >> c; cout << result << endl )
{
transform( word.begin(), word.end(), result.begin(), result.begin(), LowerComp(c, ct));
}
if( result == word )
cout << "<< Ferdich, hurrah! >>" << endl;
return 0;
}
MfG