Problem beim Speichern und Laden



  • da habe ich noch ganze prgram aber fehler zeigt mir immer da bei COLOR ich markiere euch mit ***

    [COLOR="Red"]ofstream dataus; // Speichern ***
    dataus.open("TEXT.txt", ios::out);

    for(int y=0;y <anz;y++)
    {
    dataus<<liste[y].name<<" ";
    dataus<<liste[y].kontonr<<" ";
    dataus<<liste[y].kbetrag<<endl;
    }
    dataus.close(); //Ende Speichern[/COLOR]

    [COLOR="DarkGreen"]ifstream datin; //Anfang Laden
    datin.open("konten.txt", ios::in);

    for(int y=0;!datin.eof();y++)
    {
    datin>>liste[y].name<<" ";
    datin>>liste[y].kontonr<<" ";
    datin>>liste[y].kbetrag<<endl;
    }
    datin.close(); //Ende Laden[/COLOR]

    zae++;
    system ("cls");
    gotoxy(25,13);
    cout<<"Noch ein Konto anlegen? -j,J/n,N";
    cin>>antwort;

    }
    while(antwort == 'j' || antwort == 'J' && zae < 10 );

    }

    und hier sind di fehler der mir compiler zeigt

    Compiler: Default compiler
    Building Makefile: "C:\Dev-Cpp\my projekts\kuh\Makefile.win"
    Führt make... aus
    make.exe -f "C:\Dev-Cpp\my projekts\kuh\Makefile.win" all
    g++.exe -c kjgljh.cpp -o kjgljh.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

    kjgljh.cpp: In function void kontoalg(konto*)': kjgljh.cpp:92: error: expected primary-expression before '[' token kjgljh.cpp:92: error:COLOR' undeclared (first use this function)
    kjgljh.cpp:92: error: (Each undeclared identifier is reported only once for each function it appears in.)
    kjgljh.cpp:92: error: expected ;' before "ofstream" kjgljh.cpp:93: error:dataus' undeclared (first use this function)

    kjgljh.cpp:103: error: expected primary-expression before '[' token
    kjgljh.cpp:103: error: expected ;' before "ifstream" kjgljh.cpp:104: error:datin' undeclared (first use this function)
    kjgljh.cpp:125: error: expected `}' at end of input

    make.exe: *** [kjgljh.o] Error 1

    Ausführung beendet

    könnt Ihr mir helfen bitte danke in voraus grusss bajs



  • Diese BBCode-Tags haben in einem C++ Programm auch nichts zu suchen. Wenn du dir schon die Quelltexte aus dem Internet zusammenkopierst, solltest du auch darauf achten, was dazu gehört 😃



  • Das mit speichern und laden hab ich im internent geschaut weil ich das erstes mal mach

    wenn du weisst wie das ghet kanst du mir mal erkleren wie das ghet und wie was funktioniert

    danke bajs



  • Dann empfehle ich dir mal, ein Buch durchzuarbeiten, damit du die Grundlagen verstehst.

    Bajson schrieb:

    wenn du weisst wie das ghet kanst du mir mal erkleren wie das ghet und wie was funktioniert

    Ich bin ein wenig aus der Übung - und ich weiß auch gar nichts zum Umfeld deines Programms, aber ich kannst mal versuchen:

    struct wert{...};
    
    vector<wert> liste;
    
    //schreiben
    ofstream datei(dateiname.c_str());
    for(size_t i=0;i<liste.size();++i)
    {
      datei << liste[i].v1 << ' ' << liste[i].v2 << ... << endl;
    }
    
    //schreiben
    ifstream datei(dateiname.c_str());
    wert temp;
    while(datei >> temp.v1 >> temp.v2 >> ...)
    {
      liste.push_back(temp);
    }
    

    (fortgeschrittene Anwender würden vermutlich Stream-Operatoren für die wert-Klasse schreiben)



  • hier hasst du meine ganze program schau dir mal an ok

    #include <conio.h>
    #include <iostream>
    #include <fstream>
    #include <string>
    //#include "conioex.h"
    #include <windows.h>
    
    using namespace std;
    
    struct konto				
    {
    	string name;
    	int kontonr;
    	float kbetrag;
    };
    
    const int anz = 10;
    konto liste[anz];
    
    void kontoalg (konto liste[anz]);
    void ausgeben (konto liste[anz]);
    
    int main()			//	Hauptprogramm
    {
    char wahl;
    
    	do
    	{
    	system ("cls");
    		cout<<"#### M E N U E ####"<<endl<<endl;
    		cout<<"<1> Konto Anlegen"<<endl;
    		cout<<"<2> Daten Ausgeben"<<endl;
    		cout<<"<#> Programm beenden"<<endl;
    		cout<<"Ihre Wahl ==> ";
    		cin>>wahl;
    
    		switch (wahl)
    		{
    		case '1': kontoalg (liste);
            break;
    		case '2': ausgeben (liste);
            break;
    		}
    	}
    	while(wahl != '#');
    
    getch();
    
    return 0;
    }
    
    void kontoalg(konto liste[anz])							
    
    {
    
        	char antwort;
        	int zae=0, z=0;
        	bool merker;
    
    void gotoxy (int zae,int z);
    {
    
            	do
           	{
                 	system ("cls");
    	            gotoxy(29,10);
                    cout<<"## KONTO ANLEGEN ##"<<endl<<endl;
    	            cout<<"Nachname: ";
                    gotoxy(29,12);
                	cin>>liste[zae].name;
                 	gotoxy(29,13);
    	            cout<<"Kontonr.: ";
    	            cin>>liste[zae].kontonr;
    	            gotoxy(29,14);
                	cout<<"Kontostand: ";
        	        cin>>liste[zae].kbetrag;
    
     //int main () brauch ich das überhaupt ?????
    
    	ofstream dataus;  // Speichern
    	dataus.open("TEXT.txt", ios::out);
    
    	for(int y=0;y <anz;y++)
    	{
    		dataus<<liste[y].name<<" ";
    		dataus<<liste[y].kontonr<<" ";
    		dataus<<liste[y].kbetrag<<endl;
    	}
    	dataus.close();              //Ende Speichern
    
    	ifstream datin; //Anfang Laden
    	datin.open("TEXT.txt", ios::in);
    
    	for(int y=0;!datin.eof();y++)
    	{
    	datin>>liste[y].name;
    	datin>>liste[y].kontonr;
    	datin>>liste[y].kbetrag;
    	}
    	datin.close();            //Ende Laden
    
    	zae++;
    	system ("cls");
    	gotoxy(25,13);
    	cout<<"Noch ein Konto anlegen? -j,J/n,N";
    	cin>>antwort;
    
    	}
    	while(antwort == 'j' || antwort == 'J' && zae < 10 );
    
    }
    }
    

    DAS SIND DIE FEHLER WIEDER

    #include <conio.h>
    #include <iostream>
    #include <fstream>
    #include <string>
    //#include "conioex.h"
    #include <windows.h>
    
    using namespace std;
    
    struct konto				
    {
    	string name;
    	int kontonr;
    	float kbetrag;
    };
    
    const int anz = 10;
    konto liste[anz];
    
    void kontoalg (konto liste[anz]);
    void ausgeben (konto liste[anz]);
    
    int main()			//	Hauptprogramm
    {
    char wahl;
    
    	do
    	{
    	system ("cls");
    		cout<<"#### M E N U E ####"<<endl<<endl;
    		cout<<"<1> Konto Anlegen"<<endl;
    		cout<<"<2> Daten Ausgeben"<<endl;
    		cout<<"<#> Programm beenden"<<endl;
    		cout<<"Ihre Wahl ==> ";
    		cin>>wahl;
    
    		switch (wahl)
    		{
    		case '1': kontoalg (liste);
            break;
    		case '2': ausgeben (liste);
            break;
    		}
    	}
    	while(wahl != '#');
    
    getch();
    
    return 0;
    }
    
    void kontoalg(konto liste[anz])							
    
    {
    
        	char antwort;
        	int zae=0, z=0;
        	bool merker;
    
    void gotoxy (int zae,int z);
    {
    
            	do
           	{
                 	system ("cls");
    	            gotoxy(29,10);
                    cout<<"## KONTO ANLEGEN ##"<<endl<<endl;
    	            cout<<"Nachname: ";
                    gotoxy(29,12);
                	cin>>liste[zae].name;
                 	gotoxy(29,13);
    	            cout<<"Kontonr.: ";
    	            cin>>liste[zae].kontonr;
    	            gotoxy(29,14);
                	cout<<"Kontostand: ";
        	        cin>>liste[zae].kbetrag;
    
    int main ()
    
    	ofstream dataus;  // Speichern
    	dataus.open("TEXT.txt", ios::out);
    
    	for(int y=0;y <anz;y++)
    	{
    		dataus<<liste[y].name<<" ";
    		dataus<<liste[y].kontonr<<" ";
    		dataus<<liste[y].kbetrag<<endl;
    	}
    	dataus.close();              //Ende Speichern
    
    	ifstream datin; //Anfang Laden
    	datin.open("TEXT.txt", ios::in);
    
    	for(int y=0;!datin.eof();y++)
    	{
    	datin>>liste[y].name;
    	datin>>liste[y].kontonr;
    	datin>>liste[y].kbetrag;
    	}
    	datin.close();            //Ende Laden
    
    	zae++;
    	system ("cls");
    	gotoxy(25,13);
    	cout<<"Noch ein Konto anlegen? -j,J/n,N";
    	cin>>antwort;
    
    	}
    	while(antwort == 'j' || antwort == 'J' && zae < 10 );
    
    }
    }
    

    das sind die fehler jetzt

    Compiler: Default compiler
    Building Makefile: "C:\Dev-Cpp\my projekts\kuh\Makefile.win"
    Führt make... aus
    make.exe -f "C:\Dev-Cpp\my projekts\kuh\Makefile.win" all
    g++.exe -c kjgljh.cpp -o kjgljh.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

    kjgljh.cpp: In function void kontoalg(konto*)': kjgljh.cpp:87: error: expected primary-expression before "int" kjgljh.cpp:87: error: expected;' before "int"
    kjgljh.cpp:92: error: `dataus' undeclared (first use this function)
    kjgljh.cpp:92: error: (Each undeclared identifier is reported only once for each function it appears in.)

    make.exe: *** [kjgljh.o] Error 1

    Ausführung beendet



  • Ja, du brauchst ein "int main()", allerdings als Funktionskopf einer eigenständigen Funktion und nicht irgendwo mitten in einer anderen Funktion. Mein Vorschlag ist, du fängst nochmal ganz von vorne an, C++ zu lernen, damit du ein halbwegs sauberes Programm zusammenbekommst.

    PS: Und tu dir selber einen Gefallen und verwende std::vector<> anstelle des Arrays - und nach Möglichkeit keine globalen Variablen

    PPS: Ich war mal so vrei und habe deinen Beitrag etwas nachformatiert - so ist es einfacher, darin etwas zu erkennen.



  • nei alles von vorne das alles hab ich mit buch und internent gemacht, dass was ich im buch nicht fand suche ich im internet und probierte zum lösen eizige problem ist das jetzt mit speichern und laden aber trozdem danke viel mals für deine hilfe ich probier irgendwie zum lössen ich frag mal meinem lehrer villeicht gibt er mir noch paar tipps was ich machen muss

    danke viel mals CStroll


Anmelden zum Antworten