c++ - Boost:is_any_of 产生多个错误

标签 c++ boost iterator trim

我刚刚安装了 boost,到目前为止我使用的所有函数都运行良好,但是当我在需要使用 boost::is_any_of 时使用 trim_if 时它产生了多个错误。

这是我遇到的一些错误:

error C2868: 'std::iterator_traits<_Iter>::iterator_category' : illegal syntax
for using-declaration; expected qualified-name

error C2825: '_Iter': must be a class or namespace when 
followed by '::'

error C2602: 'boost::range_iterator<C>::type' is not a member of a base class 
of 'boost::range_iterator<C>'

error C2602: 'std::iterator_traits<_Iter>::iterator_category' 
is not a member of a base class of 'std::iterator_traits<_Iter>'

error C2039: 'iterator_category' : is not a member of '`global namespace''

我已经尝试重新安装 boost,但没有用。

代码:

#include <iostream>
#include <string>

#include <boost/algorithm/string.hpp>

int main(int argc, char *argv[])
{
    std::string string = "\t\tthis is a string\t";

    boost::trim_if(string, boost::is_any_of('\t'));

    std::cout << string << std::cout;

    system("pause");
    return 0;
}

最佳答案

您的问题出在调用 boost::is_any_of('\t') 中。

is_any_of 接受一个字符序列,而您传递的是单个字符。

将您的代码更改为:

     boost::trim_if(string, boost::is_any_of("\t"));

即,使用双引号而不是单引号。

关于c++ - Boost:is_any_of 产生多个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19123492/

相关文章:

c++ - 当我使用直接初始化与 std::initializer_list 时的不同指令

arrays - swift 2.2 : Non +1 increasing iterator loops

checkbox - 带迭代器的 struts2 表在不同行中显示复选框

c++ - 是否可以使用 `std::set_intersection` 来检查两个集合是否有任何共同元素?

c++ - 为什么用关键字inline修饰构造函数会报错?

c++ - 流中奇怪的eof标志

c++ - 用消息 boost static_assert?

c++ - 交换两个 boost::adjacency_list 图,类似于 std::swap

c++ - 在 Ubuntu 上使用 boost python v1.67 和 cmake 构建基本的 C++ 项目

c++ - 从参数包中提取成员类型