首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

libconfig库中,readFile读了.cfg资料,但是却不能正确查找节点?

2013-03-10 
libconfig库中,readFile读了.cfg文件,但是却不能正确查找节点???大牛们,在调试一个别人的程序,从linux移植

libconfig库中,readFile读了.cfg文件,但是却不能正确查找节点???
大牛们,在调试一个别人的程序,从linux移植来的,里边用到了libconfig库。

在调试的时候,发现总是中途退出,单步发现,一开始运行readFile时,就没有读对,存储.cfg文件的内存在执行readFile前后没有变化,捕捉异常也没有捕捉到
贴出代码,希望大牛们能帮忙解决

声明:

protected:
libconfig::Config m_configFile;

初始化,按照路径读入.cfg

Parameters::Parameters(const std::string& confFile) : m_filename(confFile)
{
try{
m_configFile.readFile(m_filename.c_str());
   } catch (libconfig::ParseException& e) {
        std::cout << "Error reading Configuration file (" << m_filename << ")!" << std::endl;
        std::cout << "ParseException at Line " << e.getLine() << ": " << e.getError() << std::endl;
        exit(EXIT_FAILURE);
    } catch (libconfig::SettingException& e) {
        std::cout << "Error reading Configuration file (" << m_filename << ")!" << std::endl;
        std::cout << "SettingException at " << e.getPath() << std::endl;
        exit(EXIT_FAILURE);
    } catch (std::exception& e) {
        std::cout << "Error reading Configuration file (" << m_filename << ")!" << std::endl;
        std::cout << e.what() << std::endl;
        exit(EXIT_FAILURE);
    } catch (...) {
        std::cout << "Error reading Configuration file (" << m_filename << ")!" << std::endl;
        std::cout << "Unknown Exception" << std::endl;
        exit(EXIT_FAILURE);
}
}

读Tracker.Name节点:
std::string seq_name = hp.readStringParameter("Tracker.Name");

跳到这里:执行完第四行之后,到14行执行,然后程序退出了就

std::string Parameters::readStringParameter(std::string param_name) const
{
    try{
        return std::string((const char*)m_configFile.lookup(param_name));
    } catch (libconfig::ParseException& e) {
        std::cout << "Error reading Configuration file (" << m_filename << ")!" << std::endl;
        std::cout << "ParseException at Line " << e.getLine() << ": " << e.getError() << std::endl;
        exit(EXIT_FAILURE);
    } catch (libconfig::SettingException& e) {
        std::cout << "Error reading Configuration file (" << m_filename << ")!" << std::endl;


        std::cout << "SettingException at " << e.getPath() << std::endl;
        exit(EXIT_FAILURE);
    } catch (std::exception& e) {
        std::cout << "Error reading Configuration file (" << m_filename << ")!" << std::endl;
        std::cout << e.what() << std::endl;
        exit(EXIT_FAILURE);
    } catch (...) {
        std::cout << "Error reading Configuration file (" << m_filename << ")!" << std::endl;
        std::cout << "Unknown Exception" << std::endl;
        exit(EXIT_FAILURE);
}
}



[解决办法]
GDB调试时,用layout regs命令看每句C/C++对应的汇编并单步执行观察相应内存和寄存器变化。

热点排行