c++实现split函数
#include <vector>
#include <string>
#include <string.h>
bool SplitStream(const char* strSource, std::vector<char*>* strDest, const char seps)
{
if (strSource == NULL || strDest == NULL)
{
return false;
}
const int MAX_CHAR = 500;
const char* pcSrc_Copy = strSource;
char* pcOneData = new char[MAX_CHAR];
memset(pcOneData, 0, MAX_CHAR);
char p2[2] = {
0 };
memset(p2, 0, 2);
int n = 0;
while (*pcSrc_Copy != '\0')
{
char Char_Current = *pcSrc_Copy++;
if (Char_Current == seps)
{
strDest->push_back(pcOneData);
pcOneData = new char[MAX_CHAR];
memset(pcOneData, 0, MAX_CHAR);
n = 0;
}
else
{
memcpy(pcOneData + n, &Char_Current, 1);
n++;
}
}
strDest->push_back(pcOneData);
return true;
}