strtok를 사용하고 싶은데 android 개발시에는 함수가 없다면서 오류가 나더라구요


그래서 strtok를 대처할 수 있는 함수를 하나 만들어 보았어요


문자열로 이루어진 입력값으로 child1 ~ child5가 있는데 요걸 각각 분리해 내는 함수입니다.

각 child들은 공백(스페이스)로 구분지어 있는 문자열입니다.



// 자식들 문자열

std::string child_example= "child1 child2 child3 child4 child5";


// 벡터로 각각 나누어진 자식들

std::vector<std::string> Children;


//함수 호출 예제

decodeList(child_example, Children);


요렇게 호출 하고 나면 Children 벡터에 child1 ~ child5 순서로 들어가 있어요.

Children.at(0) 은 "child1" 요게 되겠지요


[함수]

void Services::decodeList(const std::string &iEncode, std::vector<std::string> &oList)

{

int head = 0;

int tail = 0;

std::string temp = iEncode;

while (tail != std::string::npos)

{

tail = temp.find(' ', head);

std::string child(temp.c_str(), head, tail);

oList.push_back(child.c_str());

temp.erase(head, tail + 1);

}

}