#define KEY_SEG "[$]"
#define VAL_SEG "[#$%]"
template<typename T1, typename T2>
std::string map2String(const std::map<T1, T2>& mapIn,string key_seg,string val_seg){
std::ostringstream oss;
oss.str("");
typename std::map<T1, T2>::const_iterator it = mapIn.begin();
typename std::map<T1, T2>::const_iterator itEnd = mapIn.end();
for(; it != itEnd; it++)
{
oss<< it->first << key_seg << it->second << val_seg;
}
return oss.str();
}
template<typename T1, typename T2>
int string2Map(const string& strIn, map<T1, T2>& mapOut,string key_seg,string val_seg)
{
if (strIn.empty())
{
return -1;
}
vector<string> vElement = TC_Common::sepstr<string>(strIn, string(val_seg));
for(unsigned int i=0; i<vElement.size(); i++)
{
string::size_type pos = vElement[i].find(key_seg);
mapOut[TC_Common::trim(vElement[i].substr(0, pos), " ")] = TC_Common::trim(vElement[i].substr(pos+1), " ");
}
return 0;
}
我的博客即将搬运同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=14jvnun1lfz7n