Problem mit Ausgabe in C++



  • Hallo !

    Ich habe ein Problem, und zwar habe ich 2 Programme die eigntlich das gleiche tun sollte.Aber ich weiß es nicht warum das 2. mehr falsche Ausgabe gibt. ich bekomme sowas raus ||||||!!2. Hat vielleicht jemand ein Ahnung was ich falsch mache ?
    Das Programm soll alle Textdateien aus dem VErzeichnis C:\READ Ausgeben.

    Vielen Dank.

    1.Programm

    #include<Afx.h>
    #include<iostream>
    using namespace std;
    
    int main ()
    {
    	 CFileFind finder;
    
       static const TCHAR szFileToFind[] = _T("C:\\READ\\*.txt"); // Alle Textdateien  suchen
    
       BOOL bResult = finder.FindFile(szFileToFind);
    
       if (bResult)
       {
          while (bResult)
    	  {
            bResult = finder.FindNextFile();                 // Nächste Datei finden
    	    cout<<(LPCTSTR)finder.GetFileName()<<endl;            // Ausgabe der gefundene Datei
    	  }
       }
       else
    	   cout<<"no text file in the directory"<<endl;
    	  return 0;
    }
    

    2. Programm

    #include<Afx.h>
    #include<iostream>
    using namespace std;
    
    LPCTSTR FindTxtFile()
    {
    
       CFileFind finder;
    
       static const TCHAR szFileToFind[] = _T("C:\\READ\\*.txt"); // Alle Textdateien  suchen
    
       BOOL bResult = finder.FindFile(szFileToFind);
    
       if (bResult)
       {
          while (bResult)
    	  {
            bResult = finder.FindNextFile();          // Nächste Datei  finden
    	    return (LPCTSTR)finder.GetFileName();// Ausgabe der gefundeneDatei
    	  }
       }
       else
    	   cout<<"no text file in the directory"<<endl;
    }
    
    int main ()
    {
    	  cout<<(LPCTSTR)FindTxtFile()<<endl; // Bildschirm ausgabe
    
    	  return 0;
    }
    

    Danke



  • Dir wurde doch hier schon erklärt, wo das Problem liegt. 🙄


Anmelden zum Antworten