开发者

Strange error with debugging and filestream in c++

开发者 https://www.devze.com 2022-12-08 09:26 出处:网络
the program I am working on has a function to read some parameters from a text file basically looking like this:

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

精彩评论

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