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 |
#include <iostream> #include <string> using namespace std; string get_line(int zeile) { string for_in; int counter=0; char array[256]; FILE *Datei; Datei = fopen("Texte.txt", "r"); do { fgets(array, 256, Datei); counter++; }while(!feof(Datei) && counter < zeile); do { for_in += array[counter]; counter++; if(array[counter] == '@') break; }while(counter < sizeof(array) / sizeof(char)); return for_in; } |
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 |
#include <iostream> #include <string> using namespace std; string get_line(int zeile) { string for_in; int counter=0; char array[256]; FILE *Datei; Datei = fopen("Texte.txt", "r"); do { fgets(array, 256, Datei); for_in += array; }while(!feof(Datei) && counter < zeile); return for_in; } |
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 |
#include <iostream> #include <string> using namespace std; string get_line(int zeile) { string for_in; int counter=0; char array[256]; FILE *Datei; Datei = fopen("Texte.txt", "r"); do { fgets(array, 256, Datei); counter++; for_in += array; for_in += "@"; }while(!feof(Datei) && counter < zeile); return for_in; } |
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 |
#include <iostream> #include <string> using namespace std; string get_line(int zeile) { string for_in; int counter=0; char array[256]; FILE *Datei; Datei = fopen("Texte.txt", "r"); do { fgets(array, 256, Datei); if (counter == zeile){ for_in += array; break; } counter++; }while(!feof(Datei)); return for_in; } |
Zitat
Der Funktion wird als Parameter die Nummer der Zeile übergeben welche ausgelesen werden soll. Nur diese Zeile soll ausgelesen werden.
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <fstream> #include <string> string getLine (int line) { ifstream file("Texte.txt") unsigned currentLine = 0; string result; while (getline(file, result)) { if (currentLine == line) return result; ++currentLine; } throw "Die Zeile gibt's gar nicht"; } |
Werbeanzeige