Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
#include <iostream> // wegen cout cin #include <fstream> // wegen Dateistreamobjekt #include <string> // wegen Datentyp string #include <windows.h> using namespace std; int main(int argc, char *argv) { srand (timeGetTime ()); char auswahl; do { cout << "(N)eues Wort" << endl; cout << "(B)eenden" << endl; cin >> auswahl; cout << endl; if (auswahl == 'N' || auswahl == 'n') { ifstream file; int zeile = 0; string loesung; string LoesungRichtig; string fileName = "C:\\Dokumente und Einstellungen\\Administrator\\Eigene Dateien\\Projekt 1\\frage.txt"; zeile = (rand()%4)+1; file.open(fileName.c_str()); if(file) { string text; int zeilen = 0; while(!file.eof()) { string txt; // Buffer getline(file, txt); text = txt + "\n"; zeilen++; if(zeile == zeilen) { cout << text; cin >> loesung; ifstream file; int zeile2 = 0; string fileName = "C:\\Dokumente und Einstellungen\\Administrator\\Eigene Dateien\\Projekt 1\\antwort.txt"; zeile2 = zeile; file.open(fileName.c_str()); if(file) { string text2; int zeilen2 = 0; while(!file.eof()) { string txt; getline(file, txt); text2 = txt + "\n"; zeilen2++; if(zeile2 == zeilen2) { LoesungRichtig = text2; } break; } } if(loesung == LoesungRichtig) { cout << "Richtig" << endl; } else { cout << "Falsch" << endl; } break; } } file.close(); } else { cout << "Fehler!"; } cin.get(); } } while (auswahl != 'b' || auswahl == 'B'); system("Pause"); return 0; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
typedef std::vector< std::string > StrList; StrList list1, list2; read( list1, file1 ); read( list2, file2 ); int randomLine = rand() % list1.size() + 1; std::cout << list1[ randomLine ]; std::string userInput; std::readline( std::cin, userInput ); if ( userInput == list2[ randomLine ] ) std::cout << "Richtig"; else std::cout << "Falsch"; |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#include <iostream> #include <fstream> #include <string> #include <cstdlib> #include <ctime> #include <cctype> int main() { std::srand(std::time(0)); char auswahl = 0; do { std::cout << "\t- (N)eues Wort\n" << "\t- (B)eenden\n"; while (!(std::cin >> auswahl) || (auswahl != 'N' && auswahl != 'n' && auswahl != 'B' && auswahl != 'b')) { std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); } if (auswahl == 'N' || auswahl == 'n') { std::ifstream file("question.dat"); if (!file) { std::cerr << "Datei konnte nicht geöffnet werden!" << std::endl; return -1; } unsigned short line = std::rand() % 4 + 1; std::string line_content; for (std::size_t i = 0; (i < line && std::getline(file, line_content)); ++i); std::cout << line_content << std::endl; std::string user_solution; std::getline(std::cin, user_solution); file.close(); file.clear(); file.open("solution.dat"); if (!file) { std::cerr << "Datei konnte nicht geöffnet werden!" << std::endl; return -1; } std::transform(user_solution.begin(), user_solution.end(), user_solution.begin(), std::toupper); for (std::size_t i = 0; (i < line && std::getline(file, line_content)); ++i); std::cout << "Diese Antwort ist " << (line_content == user_solution ? "richtig!" : "falsch!") << std::endl; } while (auswahl != 'b' || auswahl == 'B'); std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::cin.get(); } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 |
if(Loesung == RichtigeLoesung) { cout << "Richtig" << endl; } else { cout << "Falsch" << endl; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
#include <iostream> #include <fstream> #include <string> #include <cstdlib> #include <ctime> #include <cctype> #include <algorithm> int test() { std::srand(static_cast<unsigned int>(std::time(0))); char auswahl = 0; do { std::cout << "\t- (N)eues Wort\n" << "\t- (B)eenden\n"; while (!(std::cin >> auswahl) || (auswahl != 'N' && auswahl != 'n' && auswahl != 'B' && auswahl != 'b')) { std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); } if (auswahl == 'N' || auswahl == 'n') { std::ifstream file("question.dat"); if (!file) { std::cerr << "Datei konnte nicht geöffnet werden!" << std::endl; return -1; } unsigned short line = std::rand() % 4 + 1; std::string line_content; for (std::size_t i = 0; (i < line && std::getline(file, line_content)); ++i); std::cout << line_content << std::endl; std::string user_solution; std::getline(std::cin, user_solution); file.close(); file.clear(); file.open("solution.dat"); if (!file) { std::cerr << "Datei konnte nicht geöffnet werden!" << std::endl; return -1; } std::transform(user_solution.begin(), user_solution.end(), user_solution.begin(), std::toupper); for (std::size_t i = 0; (i < line && std::getline(file, line_content)); ++i); std::cout << "Diese Antwort ist " << (line_content == user_solution ? "richtig!" : "falsch!") << std::endl; } } while (auswahl != 'b' || auswahl == 'B'); std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::cin.get(); } |
C-/C++-Quelltext |
|
1 |
std::transform( str.begin(), str.end(), str.begin(), ( int (*)( int ))std::toupper ); |
C-/C++-Quelltext |
|
1 2 3 4 |
int to_upper( int c ) { return std::toupper( c ); } // ... std::transform( str.begin(), str.end(), str.begin(), to_upper ); |
C-/C++-Quelltext |
|
1 |
std::transform( str.begin(), str.end(), str.begin(), std::bind1st( std::mem_fun( &std::ctype< std::string::value_type >::toupper ), &std::use_facet< std::ctype< std::string::value_type > >( std::locale() ) ) ); |
Werbeanzeige