Naz*_*zka 18 c++ split tokenize
我已经阅读了http://www.codeproject.com/KB/recipes/Tokenizer.aspx,我希望在我的主要内容中有最后一个示例(最后,在所有图表之前)"扩展分隔符谓词",但是我当我将token_list分配给向量时,不会获得与文章作者相同的输出标记,为什么?
如何将真实结果放入列表或向量中?我想要这个:
但我有类似的东西:
来源样本:
class extended_predicate
{
public:
extended_predicate(const std::string& delimiters)
: escape_(false),
in_bracket_range_(false),
mdp_(delimiters)
{}
inline bool operator()(const unsigned char c) const
{
if (escape_)
{
escape_ = false;
return false;
}
else if ('\\' == c)
{
escape_ = true;
return false;
}
else if ('"' == c)
{
in_bracket_range_ = !in_bracket_range_;
return true;
}
else if (in_bracket_range_)
return false;
else
return mdp_(c);
}
inline void reset()
{
escape_ = false;
in_bracket_range_ = false;
}
private:
mutable bool escape_;
mutable bool in_bracket_range_;
mutable strtk::multiple_char_delimiter_predicate mdp_;
};
int main()
{
std::string str = "abc;\"123, mno xyz\",i\\,jk";
strtk::std_string::token_list_type token_list;
strtk::split(extended_predicate(".,; "),
str,
std::back_inserter(token_list),
strtk::split_options::compress_delimiters);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
mat*_*ttn 18
我在codeproject中可以得到相同的结果.你用的是什么版本的gcc?我的gcc版本如下.
g++ (GCC) 4.5.2
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Run Code Online (Sandbox Code Playgroud)
更新:我测试的代码在这里:https://gist.github.com/1037493