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 函数作用域时抛出异常