Im having trouble opening the .txt file in dev-c++, I've entered the correct name for the .txt file which is saved under the same folder, but whenever I compile and run, it will just show :
"
Begin reading file.
End reading file.

--------Welcome-------
Please choose:
etc.
"
The .txt file won't show.

below is part of my header file "Example.h:

class Example
{
      private:
              char seats[4][5][11];
              bool validate(char);
      public:
             Example(){
                      readInformation();
                      }
             int LVL, COL, ROW;
             void readInformation();
             void writeInformation();
};
void Example :: readInformation() 
{
     int i, j,k;     
     ifstream fin;
     cout<< "Begin reading file.\n";
     
     fin.open("abc.txt");
     if (!fin)
     {
               cout<<"Input file opening failed.\n";
               exit(1);
     }
     while(!fin.eof())
     {
         char c;
         fin.get(c);
         if (validate(c)) 
         {
               seats[i][j][k] =c;
               if(j==COL-1)
               {
                   j=0;
                   i++;
               }
               else
               {
                   k+=1;
                   i+=1;
               }
         }
     }

     fin.close();
     cout<< "End reading file\n" <<endl;
}

bool Example :: validate(char c)  
{ 
        if (c=='A' || c == 'B' || c == 'D' || c == 'E') 
                return true; 
        else  
                return false; 
}

//void Example :: writeInformation()

and this is my .cpp file:

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

#include "Example.h"

int main()
{
    Example ex;
    cout<< "-----Welcome-----\n";
    int choice;
    char ch;
    do
    {
         cout<< "Please choose: \n";
         cout<< "1. Display info\n 2.Make reservation\n;
         cin>>choice;
         
         switch(choice)
         {
             case 1:
                  ex.readInformation();
                  break;
             case 2:
                  cout<<"make reservation\n";
                  break;
             default:
                  cout<<"Invalid input! Enter again:\n";
                  cin>>choice;
         }
         cout<< "Continue? (Y/N)";
         cin>>ch;
         if(ch == 'N' || ch == 'n')
         {
               cout<<"Thank you and Bye!\n";
         }
    }while (ch == 'Y' || ch == 'y');
    system ("pause");
    return 0;    
}

can anyone please help, thanks.

The code you posted won't even compile.

Look at the syntax colouring of your main - line 17 is missing a closing "

sorry, I had to edit the code a bit and i forgot to put the closing "
but in my original file, i have the closing " at line 17, but still the txt file won't open.

This is an update to the cpp file:

#include <iostream>
      #include <string>
      #include <fstream>
      using namespace std;
       
      #include "Example.h"
       
      int main()
      {
      Example ex;
      cout<< "-----Welcome-----\n";
      int choice;
      char ch;
      do
      {
      cout<< "Please choose: \n";
      cout<< "1. Display info\n 2.Make reservation\n";
      cin>>choice;

      switch(choice)
      {
      case 1:
      ex.readInformation();
      break;
      case 2:
      cout<<"make reservation\n";
      break;
      default:
      cout<<"Invalid input! Enter again:\n";
      cin>>choice;
      }
      cout<< "Continue? (Y/N)";
      cin>>ch;
      if(ch == 'N' || ch == 'n')
      {
      cout<<"Thank you and Bye!\n";
      }
      }while (ch == 'Y' || ch == 'y');
      system ("pause");
      return 0;
      }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.