-
C++ Builder 6 fstream problem
Here is the code
std::ifstream releaseLog("ReleaseLog.txt");
std::ofstream outName("GGGG.txt");
if (releaseLog){
....
}
The program creates GGGG.txt in the same folder where ReleaseLog.txt is however the if statement is never executed and I don't see why. Any help would be appreciated. (The ofstream works!)
-
check the status of the file.
It's better to create an empty ifstream object and then call open() exclusively. This will enable you to examine the return code and see what went wrong:
std::ifstream releaseLog;
int stat=releaseLog.open("ReleaseLog.txt");
...
Danny Kalev
-
open() on a file stream returns void.
you could check the status with rdstate()
Code:
std::ifstream releaseLog( "ReleaseLog.txt" ) ;
std::ios_base::iostate state = releaseLog.rdstate() ;
to check for success, this is equally good:
Code:
std::ifstream releaseLog( "ReleaseLog.txt" ) ;
// ...
if (releaseLog)
{
// ...
}
it appears that the file "ReleaseLog.txt" is not in the current directory.
verify this by first deleting "GGGG.txt" and re-running the program to see where it is getting created.
-
Yeah, open returns void, which is pretty silly I must say.
Anyway, you can also use the bad() member function to see if there is a problem with the file stream object. Most likely, the file is located at a different directory so you can use its absolute path instead of just the filename.
Danny Kalev
-
IMO, the if-block is OK as written. Just add an else that examines rdstate() and whatever else to see what went wrong.
Similar Threads
-
By koraal in forum VB Classic
Replies: 3
Last Post: 11-03-2006, 04:50 PM
-
By vb_programmer in forum VB Classic
Replies: 16
Last Post: 06-23-2006, 08:10 AM
-
By aesoprock00 in forum Java
Replies: 2
Last Post: 01-28-2006, 07:18 PM
-
Replies: 0
Last Post: 12-13-2001, 01:06 PM
-
By Javier Vargas in forum VB Classic
Replies: 0
Last Post: 11-01-2000, 09:29 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|