|
From: <Mat...@Ve...> - 2005-05-19 18:02:48
|
Also when you open a stream, checking it like a boolean will fail if the
file open failed:
For example:
#include <ifstream>
#include <stdexcept>
...
ifstream foo;
if(!foo) throw runtime_error("Could not open file.");
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...]On Behalf Of Farzan
Hajian
Sent: Friday, May 20, 2005 2:31 AM
To: dev...@li...
Subject: [Dev-C++] File Existence
Hi,
I'v written a small program which simulates the DOS command "type". The
program receives
a file name form the command line. I used "fail()" function to check
existence of the received
file. I have not used "ifstream" functions a lot and I want to know
whether this is the
proper way to do so or not.
There is another function called "bad()". Please tell me what kind of
errors it can detect.
I tried it in my program and it couldn't check existence of files.
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main(int argc,char* arg[])
{
if(argc==2)
{
ifstream File(arg[1]);
char ch;
if(File.fail())
cout << "File not found!\n";
else
while(true)
{
File.get(ch);
if(File.eof())
break;
cout << ch;
}
}
system("pause>null");
}
Thanks.
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_idt12&alloc_id344&op=click
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
___________________________________________________________________
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
|