By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,809 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

exe runs from BCB IDE and on double-click, won't run from cmd line... help!

P: n/a
Hi there,

I'm working with BCB6, and I'm having a strange error. I've tried
to find a solution elsewhere, but I've got everyone scratching their
heads...

What's happening is that any exe I build in BCB6 that opens another
file will run fine if I run it from the IDE, and will run if I
double-click the exe, but when I try to run it from the command line,
it doesn't find the file specified. That is, I'll get the error code
specified for a file not found.

I've written a simple 'readlines' script to eliminate the possibility
that there's some problem with the more complex scripts I'm trying to
run, and I still have the same problem. (script attached)
The file "haarcascade_frontalface_alt.xml" is in the project folder
with the exe, and I've added that folder to the include path and
library path (not that that's necessary for this script, I think).
Obviously, for this script, I get the "error opening output file" error
message.

Anyone have any ideas what I'm doing wrong? Any and all assistance
would be greatly appreciated.

Cheers, Al.

//Code Starts
//---------------------------------------------------------------------------

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

int main()
{
string str;
ifstream haarfile("haarcascade_frontalface_alt.xml");
if (!haarfile) //test file open
{
cout << "error opening output file" <<endl;
return -1;
}
while (! haarfile.eof()) //loop through lines
{
getline(haarfile, str);
cout << str << endl;
}
haarfile.close();
return 0;
}

//---------------------------------------------------------------------------
//Code ends

Apr 24 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
al*********@gmail.com wrote:
Hi there,

I'm working with BCB6, and I'm having a strange error. I've tried
to find a solution elsewhere, but I've got everyone scratching their
heads...

BCB6?

I think you'd better find a group specific to your environment.

--
Ian Collins.
Apr 24 '06 #2

P: n/a
Sorry, I do not have a solution to your problem, but I did see some
things that should be changed in your code (see below)

al*********@gmail.com wrote:
Hi there,

I'm working with BCB6, and I'm having a strange error. I've tried
to find a solution elsewhere, but I've got everyone scratching their
heads...

What's happening is that any exe I build in BCB6 that opens another
file will run fine if I run it from the IDE, and will run if I
double-click the exe, but when I try to run it from the command line,
it doesn't find the file specified. That is, I'll get the error code
specified for a file not found. [snip]
#include <fstream>
#include <string>
#include <iostream>
using namespace std;

int main()
{
string str;
ifstream haarfile("haarcascade_frontalface_alt.xml");
if (!haarfile) //test file open
{
cout << "error opening output file" <<endl;
return -1;
IIRC the only portable values that main() can return are 0, EXIT_SUCCESS
(usually #defined to be 0), and EXIT_FAILURE. The latter two are
declared in <cstdlib>.
}
while (! haarfile.eof()) //loop through lines
{
getline(haarfile, str);
cout << str << endl;
}
This will loop one too many times. Better is:

while (getline(harrfile, str)) {
cout << str << endl;
}

See http://www.parashift.com/c++-faq-lit....html#faq-15.5 for
more info (and be sure to read the whole FAQ too, there is lots of good
stuff in there).
haarfile.close();
Not strictly necessary as the file will be closed by ifstream's
destructor when haarfile goes out of scope.
return 0;
Also not strictly necessary in C++, though some people like to have it
explicitly there.
}

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Apr 24 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.