Handling bad ifstream

if in a C++ program, im reading in files, and one of them is not read correctly for some reason, and was not opened properly, is it a good idea to close the fstream?

Answers


Fstream will automatically close when you go out of scope in C++. I don't see why you would ever need to manually close fstream in C++/


you can skip all of that by just checking to see if the file was loaded properly..

ifstream file(_path);
if(file.good()) {
    //do anything you want to the file  
}

nb. except in cases like these as a good habit you should always close files after you are finished with them.


Need Your Help

lxml returns an empty list on DTD attributes

python xml lxml dtd

I'm trying to get the attributes of a DTD element to get their default values but attributes() is returning always an empty list. Here is the code:

Sending SIGINT from keyboard to piped commands in bash

linux bash signals

If in bash I run a | b | c | d on the command line and then press ^C, which process gets the signal?