Fehler in Priemzahlenprogramm



  • danke...

    abber wenn ichs jetzt so mach:

    #include<iostream>
    using namespace std;
    
    int main()
    {
       long   priemzahl = 1;
       long   oft;
       long   test;
       float teilzahl;
       float testfloat;
    
       cout << "Anzeige aller Priemzahlen im Zahlenraum von 1 bis:\n\a";
       cin >> oft;
    
       long i;     // in einer schleife deklariert man eine variable immer wieder neu... !
    cout<<"\n1 | ";
       for(long wieder = 0; wieder < oft; ++wieder)
       {
            ++priemzahl;
            teilzahl = 1;
            int fehler;
            fehler = 0;
                  int durchlauf;
                  durchlauf = 0;
                  //cout<<"\n\n------------------------------<<>>------------------------------\n";
            for(i = 0; fehler != 1; ++i)  
            {
    
                  ++durchlauf;
                  ++teilzahl;
                  //cout<<"<--><--><--><--><-->\n";
                  //cout<<durchlauf<<"<--- durchlauf\n";
                  //cout<<teilzahl<<"<---teilzahl\n";
                  //cout<<priemzahl<<"<---priemzahl\n";
                  testfloat = priemzahl/teilzahl;
                  //cout<<testfloat<<"<--- Testfloat\n";
                  test = testfloat;
                  //cout<<test<<"<--- Test\n";
                  //cout<<fehler<<"<--- Fehler\n\n";
                                if( priemzahl == teilzahl && priemzahl <= oft)
                  {
    fstream datei;
    datei.open("priemzahlen.txt", ios::out);
    datei<<priemzahl<<" | ";
    
    datei.close();
                      cout << priemzahl <<" | ";
                                          fehler = 1;  
                      }    
                                if( test == testfloat )
                  {
    
                        fehler = 1;
                  }
    
            }
              //cout<<"\n\n------------------------------<<>>------------------------------\n";
       }
    
       cin.get();
       cin.get();
    
    }
    

    dann kommt ne fehler meldung "aggregate `std::fstream datei' has incomplete type and cannot be defined "



  • #include <fstream> vergessen sry



  • jetzt kommt:

    #include<iostream>
    #include <fstream>
    using namespace std;
    
    int main()
    {
       long   priemzahl = 1;
       long   oft;
       long   test;
       float teilzahl;
       float testfloat;
    
       cout << "Anzeige aller Priemzahlen im Zahlenraum von 1 bis:\n\a";
       cin >> oft;
    
       long i;     // in einer schleife deklariert man eine variable immer wieder neu... !
    cout<<"\n1 | ";
       for(long wieder = 0; wieder < oft; ++wieder)
       {
            ++priemzahl;
            teilzahl = 1;
            int fehler;
            fehler = 0;
                  int durchlauf;
                  durchlauf = 0;
                  //cout<<"\n\n------------------------------<<>>------------------------------\n";
            for(i = 0; fehler != 1; ++i)  
            {
    
                  ++durchlauf;
                  ++teilzahl;
                  //cout<<"<--><--><--><--><-->\n";
                  //cout<<durchlauf<<"<--- durchlauf\n";
                  //cout<<teilzahl<<"<---teilzahl\n";
                  //cout<<priemzahl<<"<---priemzahl\n";
                  testfloat = priemzahl/teilzahl;
                  //cout<<testfloat<<"<--- Testfloat\n";
                  test = testfloat;
                  //cout<<test<<"<--- Test\n";
                  //cout<<fehler<<"<--- Fehler\n\n";
                                if( priemzahl == teilzahl && priemzahl <= oft)
                  {
    fstream datei;
    datei.open("priemzahlen.txt", ios::out);
    datei<<priemzahl<<" | ";
    
    datei.close();
                      cout << priemzahl <<" | ";
                                          fehler = 1;  
                      }    
                                if( test == testfloat )
                  {
    
                        fehler = 1;
                  }
    
            }
              //cout<<"\n\n------------------------------<<>>------------------------------\n";
       }
    
       cin.get();
       cin.get();
    
    }
    

    Permission denied

    ld returned 1 exit status



  • Hast du Zugriff auf die Datei?



  • was meinst du mit zugriff?



  • Ist sie schreibgeschützt?



  • SirForce schrieb:

    Ist sie schreibgeschützt?

    Exakt. Und Willkommen, falls du der bist, für den ich dich halte. 😉



  • naja...sie existiert ja noch garnicht, weil ich das programm ja nochnicht ausführen konnte



  • Wie siehts mit ofstream aus?



  • tut mir leid...ich programmiere seit 2 tagen in c 😃
    könntest du mir kurz einmal sagen was offstream ist? 😃



  • #include<iostream>
    using namespace std;
    
    int main()
    {
       int   priemzahl = 1;
       int   oft;
       int   test;
       int   schleifenzahl;
       float teilzahl;
       float testfloat;
    
       cout << "Wieviele Primzahlen sollen Angezeigt werden?\n\a";
       cin >> oft;
    
       int i;     // in einer schleife deklariert man eine variable immer wieder neu... !
    
       for(int wieder = 0; wieder < oft; ++wieder)
       {
            ++priemzahl;
            schleifenzahl = 0;
            teilzahl = 0;
    
            for(i = 1; teilzahl < priemzahl; ++i)  
            {
                  ++teilzahl;
                  testfloat /= teilzahl;
                  test = testfloat;
    
                  if( test != testfloat )
                  {
                      fstream datei;
                      datei.open("priemzahlen.txt", ios::out);
                      datei<<priemzahl<<" | ";
    
                      datei.close();
                        cout << priemzahl <<" | ";
                        teilzahl = priemzahl;
                        i = 0;
                  }
            }
       }
    
       cin.get();
       cin.get();
    
    }
    

    so siehts jetzt aus

    Fehlermeldung;:

    32 C:\Dokumente und Einstellungen\Admin\Eigene Dateien\Geschäft\Unkommerziell\cplusplus\priemzahlentester2.cpp aggregate `std::fstream datei' has incomplete type and cannot be defined



  • #include <fstream>
    

Anmelden zum Antworten