读取xls,属性算法

 #include<iostream>
#include<vector>
#include<string>
using namespace std;
struct AttrAddon
{
int index;
int addon;
};
typedef vector<AttrAddon> AttrAddonVector;
typedef vector<string> StringVector;
namespace StringUtility
{
StringVector split(const std::string& str, const std::string& delims )
{
int maxSplits  = 0;
StringVector ret;  

int numSplits = 0;  

size_t start = 0;
size_t pos = 0;  
do   
{  
pos = str.find_first_of(delims, start);  
if (pos == start)  
{  
start = pos + 1;  
}  
else if (pos == std::string::npos || (maxSplits && numSplits == maxSplits))  
{  
ret.push_back( str.substr(start) );  
break;  
}  
else  
{  
ret.push_back( str.substr(start, pos - start) );  
start = pos + 1;  
}  

start = str.find_first_not_of(delims, start);  
++numSplits;  

} while (pos != std::string::npos);  

return ret;  
}
}
int main()
{
string str = "1:400|2:248"; //人物初始属性,如1血条:400 2攻击:248

AttrAddonVector attrAddons;
AttrAddon attrAddon = {};
if(!str.empty() && str != "0")
{
StringVector strAttrAddons = StringUtility::split(str, "|");
for (StringVector::iterator it = strAttrAddons.begin(); it != strAttrAddons.end(); ++it)
{
StringVector strAttrAddon = StringUtility::split(*it, ":");
if (strAttrAddon.size() == 2)
{
attrAddon.index = atoi(strAttrAddon[0].c_str());
attrAddon.addon = atoi(strAttrAddon[1].c_str());
if (attrAddon.index > 0 && attrAddon.addon > 0)
{
attrAddons.push_back(attrAddon);
}
}
else
{
cout<<"Logerr"<<endl;
}
}
}

for(int i=0; i<attrAddons.size(); i++)
{
cout<<attrAddons[i].index<<endl;
cout<<attrAddons[i].addon<<endl;
}
vector<AttrAddon>::iterator attr = attrAddons.begin();
while(attr != attrAddons.end())
{
cout<<(*attr).index<<endl;
cout<<(*attr).addon<<endl;
attr++;
}
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值