|
OK. I figured this out.
It was a missing include file.
Kind of strange that Visual Studio in Debug mode would reconcile these without any warnings, and then just skip over these function calls when run in Release mode or on the device.
I don't know if there is some build setting to at least warn me about this; if anyone knows of a warning, let me know.
Thanks
|
|
|
|
|
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <unistd.h> // getcwd() definition
#include <sys/param.h> // MAXPATHLEN definition
using namespace std;
int main()
{
string database;
<snip>
cout << "Select full path of Database" << endl;
cin >> database;
</snip>
How do I check the existence of a file in C++?
In perl it would be something like:
if (!database){
print "No database found\n";
exit;
}
I tried looking online for hours but all the suggestions didnt work so far..
Thanks in advance!
|
|
|
|
|
do a seatch for PathFileExists.
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
PathFileExists is a windows API and I am running C++ in linux so it doesnt work as far as I know and have been trying unless I goofed up...
|
|
|
|
|
I think you should be able to use _findfirst and _findnext on 'nix, I can't remember. They're in io.h
Or you could try to open the file and look at the function result....
|
|
|
|
|
After a lot of wrong examples from googling the web, I finally find something that works:
myFileName = file;
inp.open(myFileName.c_str(), ifstream::in);
inp.close();
if(inp.fail())
{
inp.clear(ios::failbit);
cout << "No File found " << myFileName.c_str() << endl;
exit(5);
}
else
{
cout << "Found File" << myFileName.c_str() << endl;
}
Thanks, hope this might help someone else...
Bye the way is this board only for Visual C++ or can someone working on Linux with C++ ask Qs?
|
|
|
|
|
meixiang6 wrote: Bye the way is this board only for Visual C++ or can someone working on Linux with C++ ask Qs?
We pretty much assume Visual C++ here, mostly even MFC is assumed to be used. Just in case you hadn't noticed the name of this board, it is MFC/C++.
You can ask C++ on Unix/Linux questions here, but you must let us know of it when posting your question.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
meixiang6 wrote: ...I am running C++ in linux...
It helps to mention this little requirement up front.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
|
meixiang6 wrote: How do I check the existence of a file in C++?
It's not C++, but you can use _access() .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
The standard way of checking file existence on *nix (it works on Windows as well) is stat or fstat[^], I believe.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I will give it a try tommorrow...thanks!
|
|
|
|
|
You can also try in Windows,
if ( 0 == _access( database.c_str(), 0 ) ) {
cout<<"No database found.\n"
} and the nix equivelant is
if ( 0 == access( database.c_str(), 0 ) ) {
cout<<"No database found.\n"
}
|
|
|
|
|
Hi,
I have a requirement where I need to find out whether internet is available or not. How to achieve this using VC++?
THanks
Suhas
|
|
|
|
|
|
Supra2 wrote: How to achieve this using VC++?
See here.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
i need a help to read files in the .exe file. help me to solve this problem.
|
|
|
|
|
FindResource
LockResource
etc
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Read files that are in the EXE (as a resource), or read files using an EXE?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi all,
i m write code on OnCtlColor function for color the controls.
HBRUSH CMyPropertyPage2::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor);
switch (nCtlColor)
{
case CTLCOLOR_EDIT:
pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(RGB(255,255,255));
return hbr;
case CTLCOLOR_STATIC:
LOGBRUSH logbrush;
m_brush.GetLogBrush( &logbrush );
pDC->SetTextColor(RGB(0,0,0));
pDC->SetBkColor(logbrush.lbColor);
return m_brush;
case CTLCOLOR_BTN:
case CTLCOLOR_MSGBOX:
case CTLCOLOR_DLG:
return m_brush;
default:
return m_brush;
}
}
when i use this same code for dialog box its working fine,but in case of property pages its not working fine.
the problem is that its not color the background of RadioBox,CheckBox,GroupBox type controls.
please help me for this.
and tell me solution for this.
thanks in advance
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
I don;t know the answer to your probklem, but I know where I'd start looking...
Spy++. Keep an eye where the messages go - maybe to the propertysheet, maybe to the propertypage... But you can find out!
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
Actully i dont understand that you say i have no idea of SPY please explain me.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Well, in VC6, it's a program under the tools menu, and it exists in later versions of Visual Studio also.
It monitors messages between windows, so you can see for yourself where messages end up.
(It's called Spy++ - sorry if I misnamed it before).
It takes a little practise to use, but it's very powerful.
Good luck,
Iain.
Codeproject MVP for C++, I can't believe it's for my lounge posts...
|
|
|
|
|
i m using VC2005.
thanks.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Hi,
We have planned to convert the project from VC++6.0 to VC+.net .
But i have no idea about this.
Is there any problem will come by converting or any tutorila is available for this?
Pls help me.
Anu
|
|
|
|