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: -
-
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;
-
}
-
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.
3 1474
There is no code to 'show' something when you read from the file - it just reads and stores it in seats[] array. Why must it 'show' something?
exit(1) ?
Not in C++. You need to return and error code. There is no way the function that tries to open the file has any idea of what to do if it doesn't open. That may be OK or it may not depending upon the application.
Consider this code is 125 levels deep in a program of 125,000 functions running on a server with 4000 users attached and you do exit(1). Boom! There's the C:>\ and the support staff says "Gee, I wonder where that happened".
Alyways code error handlers. In this case, call the funciton in main(), check for the error code and take the action in main().
-
1. Display info:
-
...
-
case 1:
-
ex.readInformation();
-
If you type in 1, you're telling it to read in information, but never display it. What does this seat information represent anyways? You need to choose a way to display it.
On second look, the read function doesn't make much sense either. The incrementing is all wrong.
... side note: give the guy a break with the exit(1); it was probably written by a teacher or ta, and they're not taking this beyond the classroom.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Penn Markham |
last post by:
Hello all,
I am writing a script where I need to use the system() function to call
htpasswd. I can do this just fine on the command line...works great
(see attached file, test.php). When my...
|
by: tmaster1 |
last post by:
Hi,
This ASP (Visual Studio 6) code works on other PCs (The ASP code runs locally on localhost), but it causes IE to hang on a new PC (again, the ASP code runs locally on localhost). I think it...
|
by: Jozef |
last post by:
Hello,
I am trying to put together a module and open a workspace on a database that
has a simple password (using Access XP). This is the lin that I'm having
trouble with;
Set wrk =...
|
by: Daniel Walzenbach |
last post by:
Hi,
I have a web application which sometimes throws an “out of memory”
exception. To get an idea what happens I traced some values using performance
monitor and got the following values (for...
|
by: Westbrook, Christopher L (WESTBCL04) |
last post by:
I am having some trouble, and I can't figure out why. I'm trying to use
the simple keylogger project from source forge, and then create a web
interface to open the resulting files, so people from...
|
by: curt.bathras |
last post by:
I am trying to open and read a file using the following:
BufferedStream stream = new BufferedStream(File.OpenRead(aFilename));
If the file specified by aFilename is being used by another...
|
by: MLH |
last post by:
Am having trouble with the filter property setting below.
Would like to filter the listing to car makes beginning
with "D". I'm blowing it on the filter spec somehow???
Sub OpenRecordsetX()
...
|
by: spidey12345 |
last post by:
what i need this program to do is to read paragraphs like
"st blah blh test ere
se sit blha eere w"
and then it will reformat to
"st blah...
|
by: ARC |
last post by:
Just curious if anyone is having issues with Acc 2007 once the number of
objects and complexity increases? I have a fairly large app, with many
linked tables, 100's of forms, queries, reports, and...
|
by: Matt |
last post by:
Hi friends,
Okay so well, I have quite a problem right now with a file stream. What
I am doing is to use the Cannon SDK dlls to get control over my old
Cannon A60 Camera for some surveillance...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |