the program I am working on has a function to read some parameters from a text file basically looking like this:
void ParamSet::readFrom(const std::开发者_如何学运维string filename){
std::ifstream infile(filename.c_str());
std::string line;
if(!infile.is_open())
throw(20);
/* ... read stuff ... */
infile.close();
}
which works fine when running the program. Now, when I am debugging it in Netbeans (I need to find some segfaults in another region) my exception (20) is thrown, so it says the file is not open.
Any idea what this is about and how i could resolve it?
Probably your Netbeans environment has another working folder settings so it cannot find the file. By the way, consider passing string as reference:
void ParamSet::readFrom(const std::string & filename){
std::ifstream infile(filename.c_str());
...
精彩评论