我刚刚安装了 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/