//頭文件ide
#include <string>
#include <vector>code
//-------------獲取按ch分割的子字符串--------------------------
std::vector<std::string> split(char* pStr, char ch)
{
std::vector<std::string> vec;
if (nullptr == pStr)
return vec;字符串
std::string strStr(pStr); int _off=0; std::string::size_type sizeType; while(true) { if (_off>=strStr.length()) break; sizeType=strStr.find_first_of(ch,_off); if (sizeType<=0) { _off=sizeType+1; continue; } if (sizeType==std::string::npos) { vec.push_back(strStr.substr(_off,strStr.length() - _off)); break; } vec.push_back(strStr.substr(_off,sizeType - _off)); _off=sizeType+1; } return vec;
}string
//調用實例it
std::vector<std::string> vecCapdu = split((char *)strCapdu.c_str(),';');
for (std::vector<std::string>::const_iterator itr=vecCapdu.cbegin();itr!=vecCapdu.cend();itr++)
{class
printf("%s",itr->c_str());//迭代器輸出
}迭代器