vector 排序与匹配
#include <algorithm>
// 判断是否
bool actionMatch(const std::string& strBegin, const std::string& strInput, std::string & strTail)
{
bool bResult = (strInput.size() >= strBegin.size())
&& equal(strBegin.begin(), strBegin.end(), strInput.begin());
if (bResult)
{
int iPos = strInput.compare(strInput);
strTail = strInput.substr(iPos);
}
return bResult;
}
// 匹配比较结构
typedef struct
{
std::string m_szLabel;
void* m_pAction;
}DActionInfo;
// 比较字符串
bool sortActionInfo(const DActionInfo& a, const DActionInfo& b)
{
if (a.m_szLabel > b.m_szLabel)
{
return true;
}
else
{
return false;
}
}
void test_sort()
{
// 填充输入
std::vector<std::string> arrInput;
// 填充命令
std::vector<DActionInfo> arrMatch;
arrMatch.push_back({ "ab", (void*)0 });
arrMatch.push_back({ "ac", (void*)1 });
arrMatch.push_back({ "abc", (void*)2 });
arrMatch.push_back({ "bc", (void*)3 });
arrMatch.push_back({ "ad", (void*)4 });
// 排序
std::sort(arrMatch.begin(), arrMatch.end(), sortActionInfo);
// 匹配
for (int i = 0; i< arrMatch.size();i++)
{
for (int j = 0; j < arrInput.size(); j++)
{
std::string strTail = "";
if (actionMatch(arrMatch.at(i).m_szLabel, arrInput.at(j), strTail ))
{
// 匹配成功, 退出当前循环
break;
}
}
}
return;
}
int main()
{
test_sort();
return 0;
CsvFile csv;
csv.loadFromFile("G:\\tmp\\testdata.csv");
s32 iRowCount = csv.getRowCount();
for(s32 i = 0; i < iRowCount; i++)
{
std::vector<std::string> *data = csv.getRow(i);
for (auto cell : *data)
{
printf("%s ", cell.c_str());
}
printf("\n");
}
return 0;
}