Fehler c2248



  • Guten Abend, da ich fast am verzweifeln bin, wende ich mich jetzt mal an dieses Forum. Und zwar geht es um das Einlesen eines einzelnen Strings und das Auslesen der gesamten eingelesenen Strings aus einer Datei.

    Mach ich das hier richtig?

    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    
    class Errorfail
    {
    	string buffer;
    	public:
    		ofstream dat_schr;
    		ifstream dat_ausl;
    		Errorfail(int _s)
    		{
    			int s = _s;
    			dat_schr.open("Biberror.txt", ios::out);
    			dat_schr << "Fehler bei Signatur " << s << endl;
    			dat_schr.close();
    		}
    		string message()
    		{
    			dat_ausl.open("Biberror.txt", ios::in);
    			getline(dat_ausl,buffer);
    			dat_ausl.close();
    			return buffer;
    		}
    };
    

    Bei mir kommt beim Compilieren folgende Fehlermeldung:
    *******************************************************************************

    ------ Erstellen gestartet: Projekt: ueb4, Konfiguration: Debug Win32 ------
    1>Kompilieren...
    1>medien.cpp
    1>c:\programme\microsoft visual studio 8\vc\include\fstream(802) : error C2248: "std::basic_ios<_Elem,_Traits>::basic_ios": Kein Zugriff auf private Member, dessen Deklaration in der std::basic_ios<_Elem,_Traits>-Klasse erfolgte.
    1> with
    1> [
    1> _Elem=char,
    1> _Traits=std::char_traits<char>
    1> ]
    1> c:\programme\microsoft visual studio 8\vc\include\ios(151): Siehe Deklaration von 'std::basic_ios<_Elem,_Traits>::basic_ios'
    1> with
    1> [
    1> _Elem=char,
    1> _Traits=std::char_traits<char>
    1> ]
    1> Diese Diagnose trat in der vom Compiler generierten Funktion "std::basic_ofstream<_Elem,_Traits>::basic_ofstream(const std::basic_ofstream<_Elem,_Traits> &)" auf.
    1> with
    1> [
    1> _Elem=char,
    1> _Traits=std::char_traits<char>
    1> ]
    1>c:\programme\microsoft visual studio 8\vc\include*fstream(675)* : error C2248: "std::basic_ios<_Elem,_Traits>::basic_ios": Kein Zugriff auf private Member, dessen Deklaration in der std::basic_ios<_Elem,_Traits>-Klasse erfolgte.
    1> with
    1> [
    1> _Elem=char,
    1> _Traits=std::char_traits<char>
    1> ]
    1> c:\programme\microsoft visual studio 8\vc\include\ios(151): Siehe Deklaration von 'std::basic_ios<_Elem,_Traits>::basic_ios'
    1> with
    1> [
    1> _Elem=char,
    1> _Traits=std::char_traits<char>
    1> ]
    1> Diese Diagnose trat in der vom Compiler generierten Funktion "std::basic_ifstream<_Elem,_Traits>::basic_ifstream(const std::basic_ifstream<_Elem,_Traits> &)" auf.
    1> with
    1> [
    1> _Elem=char,
    1> _Traits=std::char_traits<char>
    1> ]
    1>Code wird generiert...
    1>Kompilieren...
    1>main.cpp
    1>Code wird generiert...
    1>Kompilieren...
    1>container.cpp
    1>Code wird generiert...
    1>Das Buildprotokoll wurde unter "file://c:\Dokumente und Einstellungen\Florian Bertsch\Desktop\ueb4\ueb4\Debug\BuildLog.htm" gespeichert.
    1>ueb4 - 2 Fehler, 0 Warnung(en)
    *******************************************************************************

    Aufgrund der fettmarkierten Teile in dieser Fehlermeldung muss es sich ja um einen Fehler bei der Datei bzw. Ausgabe handeln oder?

    Wäre für Hilfe wirklich sehr dankbar. Vielen Dank im Voraus!!!



  • #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    
    class Errorfail
    {
    	string buffer;
    	public:
    		ofstream dat_schr;
    		ifstream dat_ausl;
    		Errorfail(int _s)
    		{
    			int s = _s;
    			dat_schr.open("Biberror.txt", ios::out);
    			dat_schr << "Fehler bei Signatur " << s << endl;
    			dat_schr.close();
    		}
    		string message()
    		{
    			dat_ausl.open("Biberror.txt", ios::in);
    			getline(dat_ausl,buffer);
    			dat_ausl.close();
    			return buffer;
    		}
    };
    
    int main(){}
    

    kompiliert bei mir problemlos. Ich denke mal du müsstest etwas mehr code posten

    g++ 4.1.2-0ubuntu4



  • #if !defined(ERROR_TO_FILE_H__INCLUDED)
    #define ERROR_TO_FILE_H__INCLUDED
    
    #include <fstream>
    #include <string>
    
    template<typename T>
    class error_to_file
    {
    public:
        error_to_file(const T& data) : m_data(data), m_stream("error.log", std::ios::out | std::ios::app)
        {
            std::ostringstream ss;
            ss << "FEHLER: " << m_data << std::endl;
            m_dataString = ss.str();
            m_stream << m_dataString << std::endl;
        }
        const std::string& message() const { return m_dataString; }
    
    private:
        T m_data;
        std::ofstream m_stream;
        std::string m_dataString;
    };
    
    #endif // ERROR_TO_FILE_H__INCLUDED
    


  • main.cpp

    #include "Medium.h"
    #include "container.h"
    #include <cstdlib>
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    // Globale Variablen
    
    	Container c;
    	Video* video;
             Buch* buch;
    	/*Medium* medium;*/
    
    // Prototypen:
    
    	void neues_Medium();
    	void neues_Buch();
    	void neues_Video();
    	void show_Medien();
    	void entleihe_Medien();
    	void ruecknahme_Medien();
    
    int main() 
    {
    	char auswahl = 'a';
    
    	while (auswahl != 'q')
    	{
    		cout << "\n"
    			 /*<< "(m) Neues Medium anlegen\n"*/
    			 << "(l) Medien anzeigen\n"
    			 << "(b) Neues Buch anlegen\n"
    			 << "(v) Neues Video anlegen\n"
    			 << "(e Signatur) Entleihen eines Mediums\n"
    			 << "(r Signatur) Ruecknahme eines Mediums\n"
    			 << "(q) Programm beenden\n\n";
    		cout << "Auswahl: ";
    		cin.clear(); // Eingabepuffer leeren
    		cin.sync();
    		cin >> auswahl;
    		cout << endl;
    
    		switch (auswahl) 
    		{
    			/*case 'm':
    			case 'M': neues_Medium(); 
    					break;*/
    			case 'b':
    			case 'B': neues_Buch();
    					break;
    			case 'v':
    			case 'V': neues_Video();
    					break;
    			case 'l':
    			case 'L': show_Medien(); 
    					break;
    			case 'e':
    			case 'E': entleihe_Medien(); 
    					break;
    			case 'r':
    			case 'R': ruecknahme_Medien(); 
    					break;
    			default: cout << "Bitte geben Sie einen gueltigen Befehl ein" << endl;
    		}
    	}
    	return 0;
    }
    
    /*void neues_Medium()
    {
    	bool s;
    
    	medium = new Medium();
    	medium->init_Medium();
    	s = c.add(medium);
    
    	if(s == false)
    	{
    		cout << "Element konnte nicht hinzugefügt werden";
    	}
    	else
    	{
    		cout << endl <<"Element gespeichert" << endl;
    	}
    }*/
    
    void neues_Buch()
    {
    	bool s;
    
    	buch = new Buch();
        buch->init_Buch();//Aufruf der Initialisierungsfunktion Buch::init_Buch();
        s = c.add(buch);
    
    	if(s == false)
    	{
    		cout << "Element konnte nicht hinzugefügt werden";
    	}
    	else
    	{
    		cout << endl <<"Element gespeichert" << endl;
    	}
    }
    
    void neues_Video()
    {
    	bool s;
    
    	video = new Video();
        video->init_Video();
    	s = c.add(video);
    
    	if(s == false)
    	{
    		cout << "Element konnte nicht hinzugefügt werden";
    	}
    	else
    	{
    		cout << endl <<"Element gespeichert" << endl;
    	}
    }
    
    void show_Medien()
    {	
    	Medium::printUeberschrift(); //Ausgabe der Überschrift der Tabelle
    
    	c.begin();
    
    	if (c.endOfList()== false)
    	{
    		for (c.begin(); c.endOfList() == false; c.next())
    		{
    			c.getItem()->show_Medium();
    		}
    	}
    	else 
    	{
    		cout <<"-- Bibiothek leer --"<<endl;
    	}
    }
    
    void entleihe_Medien()
    {
    	int signatur;
    	bool s = false;
    	cout << "Bitte Signatur des Mediums eingeben, welche Sie entleihen moechten" << endl << endl;
    	cin >> signatur;
    	cout << endl;
    
    	for (c.begin(); c.endOfList() == false; c.next())
    	{
    		if (c.getItem()->get_signatur() == signatur)
    		{
    			c.getItem()->entleihe_Medium();
    			s = true;
    		}
    	}
    	if (s == false)
    	{
    		cout << "Bitte geben Sie eine gueltige Signatur ein" << endl;
    	}
    }
    
    void ruecknahme_Medien()
    {
    	int signatur;
    	bool s = false;
    	cout << "Bitte Signatur des Mediums eingeben, welche Sie zuruecknehmen moechten" << endl << endl;
    	cin >> signatur;
    	cout << endl;
    
    	for (c.begin(); c.endOfList() == false; c.next())
    	{
    		if (c.getItem()->get_signatur() == signatur)
    		{
    			c.getItem()->ruecknahme_Medium();
    			s = true;
    		}
    	}
    	if (s == false)
    	{
    		cout << "Bitte geben Sie eine gueltige Signatur ein" << endl;
    	}
    }
    

    medien.cpp

    #include "Medium.h"
    #include <iostream>
    #include <iomanip> //nötig für setw()
    #include <string>
    using namespace std;
    
    //Methoden der Klasse Medium
    
    Medium::Medium()
    {
         signatur=0;
    }
    
    void Medium::init_Medium()
    {
    	LeihStatus = praesent;
    	cout << "Bitte Mediendaten eingeben: Signatur und Titel mit maximal 12 Zeichen\n\n";
    	cout << "Signatur: ";
    	cin >> signatur;
    
    	if(cin.fail() == true)
    	{
    		while (cin.fail()== true || signatur<0)
    		{
    			cout << endl << "Bitte eine gueltige Signatur ein Zahlenform eingeben" << endl;
    			cin.clear();
    			cin.sync();
    			cout << endl << "Signatur: ";
    			cin >> signatur;
    		}
    	}
    
    	cout << endl << "Titel: ";
    	cin.clear(); //Eingabepuffer löschen
    	cin.sync();
    	getline(cin,titel); //Einlesen und im String "titel" speichern
    	if(titel.length() > 12)
    	{
    		titel.erase(12,(titel.length()-12));
    	}
    }
    
    void Medium::show_Medium()
    {
    	int x = 12;
    	cout << right << setw(x) << signatur << "    " << left << setw(x) << "Medium" 
    		 << setw(x) << titel << left << setw(16) << "                    ";
    
    	if (LeihStatus == praesent)
    	{
    		cout << "vorh." << endl;
    	}
    	else 
    	{
    		cout << "entl." << endl;
    	}
    }
    
    void Medium::entleihe_Medium()
    {
    	try
    	{
    		if (LeihStatus == verliehen)
    		{
    			throw Errorfail(signatur);
    		}
    		LeihStatus = verliehen;
    		cout << endl << "Das Medium wurde entliehen." << endl << endl;
    	}
    	catch (Errorfail e)
    	{
    		outfail = e.message();
    		cout << outfail;
    	}
    }
    
    void Medium::ruecknahme_Medium()
    {
    	try
    	{
    		if (LeihStatus == praesent)
    		{
    			throw Errorfail(signatur);
    		}
    		LeihStatus = praesent;
    		cout << endl << "Das Medium wurde zurueckgenommen." << endl << endl;
    	}
    	catch (Errorfail e)
    	{
    		outfail = e.message();
    		cout << outfail;
    	}
    }
    
    void Medium::printUeberschrift()
    {
    	int x = 12;
    	cout << right << setw(x) << "Signatur" << "    " << left << setw(x) << "Typ" 
    		 << setw(x) << "Titel" << right << setw(16) << "Seiten/Dauer" 
    		 << "    " << left << setw(x) << "Status" << endl << endl;
    }
    
    //Methoden der Klasse Buch
    
    Buch::Buch():Medium()
    {     
         seitenzahl=0;                
    }
    
    void Buch::init_Buch()
    {
    	LeihStatus = praesent;
    	cout << endl << "Bitte Buchdaten eingeben: Signatur, Seitenzahl und Titel mit maximal 12 Zeichen" << endl << endl;
    	cout << "Signatur: ";
    	cin >> signatur;
    
    	if(cin.fail() == true)
    	{
    		while (cin.fail()==true || signatur<0)
    		{
    			cout << endl << "Bitte eine gueltige Signatur ein Zahlenform eingeben" << endl;
    			cin.clear();
    			cin.sync();
    			cout << endl << "Signatur: ";
    			cin >> signatur;
    		}
    	}
    	cout << endl << "Titel: ";
    	cin.clear(); //Eingabepuffer löschen
    	cin.sync();
    	getline(cin,titel);
    	if(titel.length() > 12)
    	{
    		titel.erase(12,(titel.length()-12));
    	}
    	cout << endl << "Seitenzahl: ";
    	cin.clear();
    	cin.sync();
    	cin >> seitenzahl;
    
    	if (cin.fail() == true)
    	{
    		while (cin.fail()==true || seitenzahl<0)
    		{
    			cout << endl << "Fehlerhafte Seitenzahl! Bitte erneute Eingabe." << endl;
    			cout << endl << "Seitenzahl: ";
    			cin.clear();
    			cin.sync();
    			cin >> seitenzahl;
    		}
    	} 
        return;     
    }
    
    void Buch::show_Medium()
    {
    	int x = 12;
    	cout << right << setw(x) << signatur << "    " << left << setw(x) << "Buch" 
    		 << setw(x) << titel << right << setw(16) << seitenzahl << "    " << left << setw(x);
    
    	if (LeihStatus == praesent)
    	{
    		cout << "vorh." << endl;
    	}
    	else
    	{
    		cout << "entl." << endl;
    	}
    }
    
    void Buch::entleihe_Medium()
    {
    	try
    	{
    		if (LeihStatus == verliehen)
    		{
    			throw Errorfail(signatur);
    		}
    		LeihStatus = verliehen;
    		cout << endl << "Das Medium wurde entliehen." << endl << endl;
    	}
    	catch (Errorfail e)
    	{
    		e.message();
    	}
    }
    
    void Buch::ruecknahme_Medium()
    {
    	try
    	{
    		if (LeihStatus == praesent)
    		{
    			throw Errorfail(signatur);
    		}
    		LeihStatus = praesent;
    		cout << endl << "Das Medium wurde zurückgenommen." << endl << endl;
    	}
    	catch (Errorfail e)
    	{
    		e.message();
    	}
    }
    
    //Methoden der Klasse Video
    
    Video::Video():Medium()
    {  
         spieldauer=0;             
    }
    
    void Video::init_Video()
    {
    	LeihStatus = praesent;
    	cout << "Bitte Videodaten eingeben: Signatur, Spieldauer und Titel mit maximal 12 Zeichen" << endl << endl;
    	cout << "Signatur: ";
    	cin >> signatur;
    
    	if(cin.fail() == true)
    	{
    
    		while (cin.fail()==true || signatur<0)
    		{
    			cout << endl << "Bitte eine gueltige Signatur ein Zahlenform eingeben" << endl;
    			cin.clear();
    			cin.sync();
    			cout << endl << "Signatur: ";
    			cin >> signatur;
    		}
    	}
    	cout << endl << "Titel: ";
    	cin.clear();
    	cin.sync();
    	getline(cin,titel);
    	if(titel.length() > 12)
    	{
    		titel.erase(12,(titel.length()-12));
    	}
    	cout << endl << "Spieldauer: ";
    	cin.clear();
    	cin.sync();
    	cin >> spieldauer;
    
    	if (cin.fail() == true)
    	{
    		while (cin.fail()==true || spieldauer<0)
    		{
    			cout << endl << "Fehlerhafte Spieldauer! Bitte erneute Eingabe." << endl;
    			cout << endl << "Spieldauer: ";
    			cin.clear();
    			cin.sync();
    			cin >> spieldauer;
    		}
    	} 
        return;
    }
    
    void Video::show_Medium()
    {
    	int x = 12;
    	cout << right << setw(x) << signatur << "    " << left << setw(x) << "Video" 
    		 << setw(x) << titel << right << fixed << setprecision(2) << setw(16) << spieldauer << "    " << left << setw(x);
    
    	if (LeihStatus == praesent)
    	{
    		cout << "vorh." << endl;
    	}
    	else
    	{
    		cout << "entl." <<endl;
    	}
    }
    
    void Video::entleihe_Medium()
    {
    	try
    	{
    		if (LeihStatus == verliehen)
    		{
    			throw Errorfail(signatur);
    		}
    		LeihStatus = verliehen;
    		cout << endl << "Das Medium wurde entliehen." << endl << endl;
    	}
    	catch (Errorfail e)
    	{
    		e.message();
    	}
    }
    
    void Video::ruecknahme_Medium()
    {
    	try
    	{
    		if (LeihStatus == praesent)
    		{
    			throw Errorfail(signatur);
    		}
    		LeihStatus = praesent;
    		cout << endl << "Das Medium wurde zurückgenommen." << endl << endl;
    	}
    	catch (Errorfail e)
    	{
    		e.message();
    	}
    }
    

    container.cpp

    #include "container.h"
    using namespace std;
    
    // Methoden der Klasse Container
    
    Knoten::Knoten()
    {
    	next = NULL;
    	item = NULL;
    }
    
    Container::Container()
    {
    	first = new Knoten();
    	iterator = NULL;
    }
    
    bool Container::add(T* element) //Returnwert zur Fehlerkennung
    {
    	try
    	{
    		iterator = new Knoten();
    	}
    	catch(bad_alloc)
    	{
    		return false;
    	}
    
    	iterator->next = first->next;
    	first->next = iterator;
    	iterator->item = element;
    
    	return true;
    }
    
    void Container::begin()
    {
    	iterator = first->next;
    }
    
    void Container::next()
    {
    	iterator = iterator->next;
    }
    
    T* Container::getItem()
    {
    		return iterator->item;
    }
    
    bool Container::endOfList()
    {
    	if (iterator != NULL)
    		return false;
    	else
    		return true;
    }
    

    container.h

    #ifndef CONTAINER_H
    #define CONTAINER_H
    
    #include "Medium.h"
    using namespace std;
    
    class Knoten
    {
    	friend class Container; //Klasse Container erhält Zugrif auf alle Elemente von Klasse Knoten
    	Knoten* next;
    	T* item;
    	public:
    		Knoten();
    };
    
    class Container 
    {
    	Knoten* first;
    	Knoten* iterator; //Zeiger auf das aktuelle Containerelement
    
    	public:
    		Container(); //Konstruktor
    		bool add(T* element);
    		void begin();
    		void next();
    		T* getItem();
    		bool endOfList();
    };
    
    #endif
    

    Medium.h

    #ifndef MEDIUM_H
    #define MEDIUM_H
    
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    
    enum Status {praesent, verliehen};
    string outfail;
    
    class Errorfail
    {
    	string buffer;
    	public:
    		ofstream dat_schr;
    		ifstream dat_ausl;
    		Errorfail(int _s)
    		{
    			int s = _s;
    			dat_schr.open("Biberror.txt", ios::out);
    			dat_schr << "Fehler bei Signatur " << s << endl;
    			dat_schr.close();
    		}
    		string message()
    		{
    			dat_ausl.open("Biberror.txt", ios::in);
    			getline(dat_ausl,buffer);
    			dat_ausl.close();
    			return buffer;
    		}
    };
    
    class Medium
    {
    	protected://Zugriff nur aus abgeleiteten Klassen möglich.
    		string titel;
    		Status LeihStatus;
    		int signatur;
    
    	public:	
    		Medium();
    			~Medium(); //Destruktor
    		void init_Medium();
    			virtual void show_Medium();		  //virtual nötig zum Aufruf von show_Medium in den abgeleiteten Klassen
    			virtual void entleihe_Medium()=0; // rein virtuelle Funktion, abstrakte Basisklasse
    		void ruecknahme_Medium();
    		static void printUeberschrift();
    		int get_signatur() 
    		{
    			return signatur;
    		}			
    };
    
    typedef Medium T;
    
    class Buch : public Medium
    {
    	int seitenzahl;
    
    	public:
    		Buch();
    			~Buch(){} //Destruktor
    		void init_Buch();
    		void show_Medium();
    		void entleihe_Medium();
    		void ruecknahme_Medium();
    		int get_signatur() 
    		{
    			return signatur;
    		}
    };
    
    class Video : public Medium
    {
    	double spieldauer;
    
    	public:
    		Video();
    			~Video(){} //Destruktor
    		void init_Video();
    		void show_Medium();
    		void entleihe_Medium();
    		void ruecknahme_Medium();
    		int get_signatur() 
    		{
    			return signatur;
    		}
    };
    #endif
    


  • hmm

    #if !defined(ERROR_TO_FILE_H__INCLUDED)
    #define ERROR_TO_FILE_H__INCLUDED
    
    #include <fstream>
    #include <string>
    
    template<typename T>
    class error_to_file
    {
    public:
        error_to_file(const T& data) : m_data(data), m_stream("error.log", std::ios::out | std::ios::app)
        {
            std::ostringstream ss;
            ss << "FEHLER: " << m_data << std::endl;
            m_dataString = ss.str();
            m_stream << m_dataString << std::endl;
        }
        const std::string& message() const { return m_dataString; }
    
    private:
        T m_data;
        std::ofstream m_stream;
        std::string m_dataString;
    };
    
    #endif // ERROR_TO_FILE_H__INCLUDED
    
    #if !defined(INTERFACE_MEDIUM__INCLUDED)
    #define INTERFACE_MEDIUM__INCLUDED
    
    #include <string>
    #include <iostream>
    #include <iomanip>
    
    class IMedium
    {
    public:   
    	IMedium() : m_lend(false), m_sig(0) {}
    	~IMedium()							{}
    
    public:
    	virtual void init()	
    	{ 
    		std::cout << "Signatur: " << std::flush; std::cin >> m_sig; 
    		std::cout << "Titel: " << std::flush; std::getline(std::cin, m_title); 
    		if (m_title.length() > 12) m_title.erase(12);
    	}
    
    	virtual void show()		
    	{  
    		std::cout << std::right << std::setw(12) << m_sig << "    " << std::left << std::setw(12) << "Medium" << std::setw(12) << m_title << std::left << std::setw(16) << "                   " << (m_lend ? "ausg." : "vorh.") << std::endl;	
    	}
    
    	virtual void lend()		
    	{ 
    		try
    		{
    			if (m_lend == true)
    				throw error_to_file<int>(m_sig);
    			m_lend = true;
    			std::cout << std::endl << "Das Medium wurde verliehen!" << std::endl << std::endl;
    		}
    		catch (const error_to_file<int>& e)	{	std::cerr << e.message() << std::endl;	}
    	}
    
    	virtual void recede()
    	{
    		try
    		{
    			if (m_lend == false)
    				throw error_to_file<int>(m_sig);
    			m_lend = false;
    			std::cout << std::endl << "Das Medium wurde zurückgenommen!" << std::endl << std::endl;
    		}
    		catch (const error_to_file<int>& e)	{	std::cerr << e.message() << std::endl;	} 
    	}
    
    public:
    	int get_signature() const	{	return m_sig;	}      
    
    protected:
    	std::string		m_title;
    	bool			m_lend;
    	int				m_sig;
    }; 
    
    #endif // INTERFACE_MEDIUM__INCLUDED
    
    #if !defined (VIDEO_H__INCLUDED)
    #define VIDEO_H__INCLDED
    
    class Video : public IMedium
    {
    public:
    	Video() : m_timePlay(0.0)	{}
    	~Video()					{}
    
    public:
    	void init()
    	{
    		std::cout << ".Video:" << std::endl;
    		do {
    			std::cin.clear(); 
    			std::cin.sync();
    			std::cout << ".:Signatur: " << std::flush;
    		} while (!(std::cin >> m_sig));
    		std::cout << ".:Titel: " << std::flush;
    		std::getline(std::cin, m_title);
    		m_title.erase(12);
    		do {
    			std::cin.clear(); 
    			std::cin.sync();
    			std::cout << ".:Spieldauer: " << std::flush;
    		} while (!(std::cin >> m_timePlay));
    	}
    
    	void show()
    	{
    		std::cout << std::right << std::setw(12) << m_sig << "    " << std::left << std::setw(12) << "Video" << std::setw(12) << m_title << std::right << std::fixed << std::setprecision(2) << std::setw(16) << m_timePlay << "    " << std::left << std::setw(12) << (m_lend == true ? "ausg." : "vorh.") << std::endl;
    	}
    
    private:
    	double m_timePlay;
    }; 
    
    #endif // VIDEO_H__INCLUDED
    
    #if !defined (BOOK_H__INCLUDED)
    #define BOOK_H__INCLUDED
    
    class Book : public IMedium
    {
    public:
    	Book() : m_countPage(0)		{}
    	~Book()						{}
    
    public:
    	void init()
    	{
    		std::cout << ".Buch:" << std::endl;
    		do {
    			std::cin.clear(); 
    			std::cin.sync();
    			std::cout << ".:Signatur: " << std::flush;
    		} while (!(std::cin >> m_sig));
    		std::cout << ".:Titel: " << std::flush;
    		std::getline(std::cin, m_title);
    		m_title.erase(12);
    		do {
    			std::cin.clear(); 
    			std::cin.sync();
    			std::cout << ".:Seitenanzahl: " << std::flush;
    		} while (!(std::cin >> m_countPage));
    	}
    
    	void show()
    	{
    		std::cout << std::right << std::setw(12) << m_sig << "    " << std::left << std::setw(12) << "Buch" << std::setw(12) << m_title << std::right << std::setw(16) << m_countPage << "    " << std::left << std::setw(12) << (m_lend == true ? "ausg." : "vorh.") << std::endl;
    	}
    
    private:
    	unsigned short	m_countPage;
    }; 
    
    #endif // BOOK_H__INCLUDED
    
    int main()
    {
    	std::vector<IMedium> media;
    	char sel = 'a';
    
        while (sel != 'q')
        {
    		std::cout << "(l) Medien anzeigen" << std::endl;
    		std::cout << "(b) Neues Buch anlegen" << std::endl;
    		std::cout << "(v) Neues Video anlegen" << std::endl;
    		std::cout << "(e Signatur) Entleihen eines Mediums" << std::endl;
    		std::cout << "(r Signatur) Ruecknahme eines Mediums" << std::endl;
    		std::cout << "(q) Programm beenden" << std::endl;
    
    		do {
    			std::cin.clear();
    			std::cin.sync();
    			std::cout << "Auswahl: " << std::flush;
    		} while (!(std::cin >> sel));
    
            switch (sel)
            {
                case 'b':
                case 'B': 
    				{
    					media.push_back(Book());
    					media[media.size() - 1].init();
    				} break;
                case 'v':
                case 'V': 
    				{
    					media.push_back(Video());
    					media[media.size() - 1].init();
    				} break;
                case 'l':
                case 'L': 
    				{
    					for (std::vector<IMedia>::iterator it = media.begin(); it != media.end(); ++it)
    						(*it).show();
    				} break;
                case 'e':
                case 'E':
    				{
    					int sig;
    					do {
    						std::cin.clear();
    						std::cin.sync();
    						std::cout << "Signatur: " << std::flush;
    					} while (!(std::cin >> sel));
    
    					bool found = false;
    					for (std::vector<IMedia>::iterator it = media.begin(); it != media.end(); ++it)
    						if ((*it).get_signatur() == sig) { found = true; (*it).lend(); break; }
    
    						std::cerr << "Kein Medium mit dieser Signatur vorhanden!" << std::endl;
    				} break;
                case 'r':
                case 'R': 
    				{
    					int sig;
    					do {
    						std::cin.clear();
    						std::cin.sync();
    						std::cout << "Signatur: " << std::flush;
    					} while (!(std::cin >> sel));
    
    					bool found = false;
    					for (std::vector<IMedia>::iterator it = media.begin(); it != media.end(); ++it)
    						if ((*it).get_signatur() == sig) { found = true; (*it).recede(); break; }
    
    						std::cerr << "Kein Medium mit dieser Signatur vorhanden!" << std::endl;
    				} break;
                default: 
    				std::cerr << "Menüpunkt nicht vorhanden!" << std::endl;
            }
        }
    }
    

    🙂


  • Mod

    (D)Evil: Das ist ganz schön lang, dafür dass es nicht durch den Compiler gejagt wurde 😉

    Das Problem ist

    throw Errorfail(signatur);
    

    Dafür muss Errorfail kopiert werden, was nicht möglich ist, da es Streammember hat und Streams per se nicht kopierbar sind. Es sind noch ein paar mehr Probleme im Code, aber die willst du sicher selber finden.


Anmelden zum Antworten