Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Umgang mit fstream

Empfohlene Antworten

Veröffentlicht

Hi Leute

Ich bins nochmal, habe diesmal folgendes Problem

Ich wollte mit einem fstream eine Datei öffnen und anschließend die einzelnen Zeilen einlesen und durchnumerieren .

Hatt aber nicht geklappt!!

Kan mir vieleicht jemand sagen wie man soetwas am besten macht ???:old

Gruß neuling 2010

Hier ist mein Code

class Bibiothek{

private:

	vector<GatterTyp*> bibElemente;

	string datei;

public:

	Bibiothek();

	~Bibiothek() {}

	string getPfad() {return datei}

	GatterTyp*getbibElemente(string typ);

	void dateiAusgabe();

	void dateiAuswerten();

	void pfadEinlesen();

	inline void openError();

	inline void readError();

};
#include "Klassen.h"

#include <vector>

#include <fstream>

GatterTyp*Bibiothek::getbibElemente(string typ)

{   GatterTyp e;

	vector<GatterTyp*>::iterator it;

	for(it=bibElemente.begin();it!=bibElemente.end();++it)

	{if(e.getname()==typ){return bibElemente;break;};};

}


void Bibiothek::dateiAusgabe()

{fstream meineBibiothek ("bib.txt");

if(!meineBibiothek){openError()}

string zeile;

int i;

while(!meineBibiothek.eof())

{i++;


getline(meineBibiothek,zeile)

cout<<i<<":"<<zeile<<endl;


}

meineBibiothek.close();

}

void CBibliothek:: pfadEinlesen() {

	cout << "Pfad und Name der Bibliothek-Datei:" << endl;

	cin >> datei;

}



inline void Bibiothek::openError()

{cout<<"Fehler beim oefnen der Datei!!"<<endl;

exit(1);}

:)

Bearbeitet von Klotzkopp
Code-Tags hinzugefügt

Jetzt hast du den Code hingeklatscht (die Code-Tags fügst du beim nächsten Mal bitte selbst ein), aber was nicht klappt, hast du nicht geschrieben.

Ein paar allgemeine Hinweise:

Benutz ifstream zu Lesen, ofstream zum Schreiben.

Die Prüfung mit eof ist falsch. Eof liefert erst dann true, wenn das Lesen schon einmal fehlgeschlagen ist. Du kannst einfach mit while(getline(meineBibiothek,zeile)) arbeiten.

Close brauchst du auch nicht aufzurufen, das macht der Destruktor.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.