// Tree with string objects // Author: Sven Eisenhauer // Date: 20.06.05 #include using std::cout; using std::cerr; using std::cin; using std::endl; #include using std::ofstream; using std::ifstream; using std::ios; using std::getline; #include using std::string; #include using std::setw; #include #include #include #include typedef std::map< string,string,std::less< string > > wordpairs; int main() { wordpairs en_de,de_en; wordpairs *pairPtr; string word; string en; string de; int pos; int end; ifstream inFile( "Words.txt", ios::in ); if( !inFile ) { cerr << "Input-Datei konnte nicht geoeffnet werden." << endl; exit( 1 ); } while( getline(inFile,word)) { //cout << word << endl; pos=word.find_first_of(','); end=word.size(); en.assign(word,0,pos); de.assign(word,pos+1,end); // cout << de << "\t " << en << endl; en_de.insert(wordpairs::value_type(en,de)); de_en.insert(wordpairs::value_type(de,en)); } inFile.close(); cout << "Englisch - Deutsch" << endl << endl; for (wordpairs::const_iterator it=en_de.begin(); it!=en_de.end(); it++) { cout<< setw(30) << it->first << "\t "<second<< endl; } cout << endl << endl<< "Deutsch - Englisch"<first << "\t "<second<< endl; } srand(time(0)); int lang=(rand()%2); if (lang==0) pairPtr=(&en_de); else pairPtr=(&de_en); int posi=(rand()%(pairPtr->size())); wordpairs::const_iterator it3=(pairPtr->begin()); int counter=0; int stop=0; cout << endl << endl; string eingabe; while ( it3!=(pairPtr->end()) && stop==0) { it3++; counter++; if(posi==counter) { cout << it3->first << endl; cout <<"Ihre Uebersetzung: "; cin>>eingabe; cout << "Ihre Eingabe: " << eingabe << endl; cout << "Richtig ist:" << it3->second << endl; stop=1; } } return 0; }