加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

POCO库的使用

发布时间:2020-12-15 23:40:16 所属栏目:百科 来源:网络整理
导读:最近在找网络库的时候发现了POCO这个库,里面的配置文件接口用着挺舒服的。TCP没有使用因为windows下面是select模式,效率不够。数据库用的是ODBC效率也不够,日志系统没有glog好,所以日志用的glog,别的还没有研究,有空的时候再补上。 wstring s2w(const

最近在找网络库的时候发现了POCO这个库,里面的配置文件接口用着挺舒服的。TCP没有使用因为windows下面是select模式,效率不够。数据库用的是ODBC效率也不够,日志系统没有glog好,所以日志用的glog,别的还没有研究,有空的时候再补上。

wstring s2w(const string& str)
{
size_t num = 0;
vector<wchar_t>buf( str.size()*2 + 2 );
_locale_t local = _create_locale(LC_ALL,"chs");
//if failed set buf empty string and num = 0
_mbstowcs_s_l(&num,&buf[0],buf.size(),str.c_str(),_TRUNCATE,local);
_free_locale(local);
return &buf[0];
}


中文路径的支持

str = "D:我的文档config.xml";

wstring wstr = s2w(str);

Poco::UnicodeConverter::toUTF8(wstr,str);

AutoPtr<Poco::Util::XMLConfiguration> cfg(new Poco::Util::XMLConfiguration(str.c_str()));

m_dbIp = cfg->getString("database.ip");
m_dbPort = cfg->getString("database.port");
m_dbUser = cfg->getString("database.userName");
m_dbPwd = cfg->getString("database.password");


配置文件格式如下;

<config> <ftp> <ip>192.168.18.131</ip> <port>21</port> <userName>ANONYMOUS</userName> <password></password> </ftp> <database> <ip>192.168.18.246</ip> <port>1433</port> <userName>sa</userName> <password>`123qwer</password> </database> </config>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读