开发者

Strange error with debugging and filestream in c++

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());
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜