Datei wird immer wieder überschrieben



  • Hey,
    ich hab das Problem das meine Datei immer wieder überschrieben wird obwohl ich einfach nur ein paar Informationen dranhängen möchte.
    Code:

    #include <iostream>
    #include <fstream>
    
    using namespace std; 
    
    struct TrackInfo 
    { 
        char Artist[128]; 
        char Album[128];
        char Titel[128];
        char Pfad[128]; 
    }; 
    
    void ReturnThis()
    {
        return;
    }
    
    int main()
    {
        fstream File("RAZR.dat", ios::out|ios::ate); 
        if (File.is_open()) 
        { 
            TrackInfo TrackIn; 
            cout << "Artist: "; 
            cin.getline(TrackIn.Artist, 128); 
            cout << "Album: "; 
            cin.getline(TrackIn.Album, 128); 
            cout << "Titel: "; 
            cin.getline(TrackIn.Titel, 128); 
            cout << "Pfad: ";
            cin.getline(TrackIn.Pfad, 128); 
    
            File.write((const char*)&TrackIn, sizeof(TrackIn)); 
        } 
        File.close(); 
    
        File.open("RAZR.dat", ios::in|ios::binary); 
        if (File.is_open()) 
        { 
            TrackInfo TrackIn; 
            while (File.read((char*)&TrackIn, sizeof(TrackIn))) 
                cout << "Artist: " << TrackIn.Artist << " Album: "  << TrackIn.Album  << " Titel: "  << TrackIn.Titel << " Pfad: " << TrackIn.Pfad << endl; 
        }
    
        while(1)
        {
            ReturnThis();
        }
    
        return 0;
    }
    

    LG


  • Mod

    Entweder out und app, oder out und in und ate, je nachdem, was besser für dich passt.

    Du solltest beim Schreiben wohl auch binary setzen.


Anmelden zum Antworten