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 content of the .txt file won't show.
below is part of my header file "Example.h:
and this is my cpp file:
this is what I have in my abc.txt file:
A B B A
A B B A
A B B A
A B B A
A B B A
D B B D
D B B D
D B B D
D B B D
D B B D
D B B D
D B B D
D B B D
can anyone please help, thanks.
"
Begin reading file.
End reading file.
--------Welcome-------
Please choose:
etc.
"
The content of the .txt file won't show.
below is part of my header file "Example.h:
Code:
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()
Code:
#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; }
A B B A
A B B A
A B B A
A B B A
A B B A
D B B D
D B B D
D B B D
D B B D
D B B D
D B B D
D B B D
D B B D
can anyone please help, thanks.
Comment