내가이 당신이하고 싶은 일을 할 것이라고 생각 부스트 라이브러리를 사용할 수있는 경우 - 귀하의 질문에 조금 불분명으로
#include <iostream>
#include <vector>
#include <string>
#include <boost/tokenizer.hpp>
int main(int argc, char *argv[])
{
std::string data("[this],[is],[some],[weird],[fields],[data],[I],[want],[to],[split]");
boost::tokenizer<boost::char_separator<char> > tokens(data, boost::char_separator<char>("],["));
std::vector<std::string> words(tokens.begin(), tokens.end());
for(std::vector<std::string>::const_iterator i=words.begin(),end=words.end(); i!=end; ++i)
{
std::cout << '\'' << *i << "'\n";
}
return 0;
}
이 다음과 같은 출력을 생성하지만 완전히 확실하지를
'this'
'is'
'some'
'weird'
'fields'
'data'
'I'
'want'
'to'
'split'
당신은 구분 기호의 배열을 전달, 그리고 어느 하나에'strtok' 토큰 화를 갖고 싶어한다는 것을 의미합니까 그들? –
사실, 아니, 그 뜻은 반대입니다. 'strtok'이'[,]'를 ** 단일 ** 분리 문자로 취급하고 싶습니까? –
단지 C 함 수와'strtok'을 C++에서 사용하지 마십시오. 함정이 너무 많아서 파괴적입니다. 'string'과'find'를 사용하십시오. –