分割 v,v 类型字符串代码块
void SetSub(string src, vector<int>& value)
{
size_t size = 0;
for (size_t i = 0; i < src.length(); ++i)
{
if (src.at(i) == ',')
{
size++;
}
}
value = vector<int>(size + 1, 0);
int index = 0;
int count = 0;
while ((index = src.find(',')) != -1)
{
value[count] = atoi(src.substr(0, index).c_str());
src.erase(0, index + 1);
count++;
}
value[count] = atof(src.c_str());
}
分割 k,v|k,v 类型字符串代码块
void SetSub(string src, std::map<int,int>& value)
{
size_t size = 0;
for (size_t i = 0; i < src.length(); ++i)
{
if (src.at(i) == '|')
{
size++;
}
}
vector<string> temp = vector<string>(size + 1);
int index = 0;
int count = 0;
while ((index = src.find('|')) != -1)
{
temp[count] = src.substr(0, index);
src.erase(0, index + 1);
count++;
}
temp[count] = src;
for (int i=0;i<=count;i++)
{
int k = 0;
string temp_str = temp[i];
while ((k = temp_str.find(',')) != -1)
{
int id = atoi(temp_str.substr(0, k).c_str());
if (id!=0)
{
value[id] = i;
}
temp_str.erase(0, k + 1);
}
int id_end = atof(temp_str.c_str());
if (id_end!=0)
{
value[id_end] = i;
}
}
}