std::ifstream 在析构函数中抛出异常

void load(const std::string &path, std::string &buffer, uint32 open_mode /*= std::fstream::in*/)
{
    std::ifstream ifs;
    ifs.open(path.c_str(), open_mode);

    if (!ifs.is_open())
    {
        return;
    }

    buffer.append(std::istreambuf_iterator<char>(ifs), std::istreambuf_iterator<char>());
    ifs.close();
}

int main(int argc, char *argv[])
{
    std::string buffer;
    load("F:\\zt\\build\\x64\\Debug\\config.xml", buffer);
    std::cout << buffer << std::endl;

    return 0;
}

config.xml 文件定义如下

<?xml version="1.0"?>
<CommonRedis>
    <ServerList>
        <Character Host="127.0.0.1" Port="6379" Password="123456" />
    </ServerList>
</CommonRedis>
<CommonMySQL>
    <ServerList>
        <Character Host="127.0.0.1" Port="6379" UserName="root" Password="123456" Database="game" />
    </ServerList>
</CommonMySQL>
<CommonSocket>
    <SocketBuffer ReceiveBuffSize="60000" SendBuffSize="6000" />
</CommonSocket>

以上代码在离开 main 函数作用域时抛出异常

filesystem_utils这个类怎么实现的
它本身有没有问题

如果是系统类库,假设没有bug
那么看看返回什么异常,是不是文件没找到无法读取,xml格式错误,解析错误,或者有中文编码等问题

把这个函数贴出来:this->parse

void load(const std::string &path, std::string &buffer, uint32_t open_mode /*= std::fstream::in*/)
{
std::ifstream ifs;
ifs.open(path.c_str(), open_mode);

if (!ifs.is_open())
{
    return;
}

buffer.append(std::istreambuf_iterator<char>(ifs), std::istreambuf_iterator<char>());
ifs.close();

}

int main()
{
std::string buffer;
load("d:\config1.xml", buffer, std::fstream::in);
std::cout << buffer << std::endl;

return 0;

}
以上代码通过测试,可以正常输出XML的内容。