如何使用正则表达式和提升转换迭代器标记和转换 c 字符串
How to tokenize and transform a c-string using regex and boost transform iterators?
我尝试用分号分隔的数字标记化c字符串并将它们存储在向量中。这是我的简化方法
auto string = "1;2;3;4";
const std::regex separator {";"};
std::cregex_token_iterator t_begin{string, string + strlen(string), separator, -1};
std::cregex_token_iterator t_end{};
auto begin = boost::make_transform_iterator(t_begin, atoi);
auto end = boost::make_transform_iterator(t_end, atoi);
std::vector<int> result{begin, end};
我收到错误消息:
error: no type named 'type' in 'boost::mpl::eval_if<boost::is_same<boost::iterators::use_default, boost::iterators::use_default>, boost::result_of<const int(std::sub_match<const char*>&)>, boost::mpl::identity<boost::iterator::use_default> >::f_{aka struct boost::result_of<const int(const std::sub_match<const char*>&)>}'
typedef typename f_::type type;
我不明白。
std::cregex_token_iterator
在取消引用时返回相应类型的std::sub_match
。在这种情况下,它是一对const char*
指针,因此可能的解决方案如下:
auto f = [] (std::csub_match m) { return std::atoi(m.first); };
auto begin = boost::make_transform_iterator(t_begin, f);
auto end = boost::make_transform_iterator(t_end, f);
演示
相关文章:
- wcstombs_s(),转换字符串的长度
- 使用 CStringW/CStringA 和 CT2W/CT2A 转换字符串有什么区别?
- 无法转换字符串插入函数的参数
- 转换字符串向量:基于先前的值跳过元素
- 从中间器转换字符串不起作用,出了什么问题?
- 失败的证明转换字符串到枚举类
- 如何使用正则表达式和提升转换迭代器标记和转换 c 字符串
- 使用java jni时转换字符串类型
- 如何避免在转换字符串令牌流时重复istringstream构造
- 阿托伊未正确转换字符串
- C++,转换字符串,使连续下划线序列变为单个下划线
- 使用长算术转换字符串
- 转换字符串十进制数时的精度
- 将词法转换字符串提升为双精度
- 使用marshal_as函数转换字符串的性能
- C++不会从数据转换字符串
- 无论如何,在c++ /Qt中转换字符串到结构中的字段
- C++ 隐式类型转换字符串 -> int?
- 转换字符串到浮点数,c++实现
- 用于转换字符串大小写的函数