Header file
#include <string>
#include <vector>
-------------gets the substring separated by 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;
}
Invoke instance
Std::vector<std::string> VECCAPDU = Split ((char *) strcapdu.c_str (), '; ');
For (Std::vector<std::string>::const_iterator Itr=veccapdu.cbegin (); Itr!=veccapdu.cend (); itr++)
{
printf("%s",itr->c_str());//迭代器输出
}
C + + implements string-by-character segmentation of source code