#include <boost/algorithm/string.hpp>
#include <vector>
#include <iostream>
#include <string>
using namespace std;
using namespace boost;
int main(int, char **)
{
string test = "h:help";
vector<string> v;
iter_split(v, test, first_finder("h:"));
copy(v.begin(), v.end(), ostream_iterator<string>(cout, "\n"));
return 0;
}
这个简单的代码不会使用-std=c++0x
在GCC 4.6中编译;但是,它将在较旧的编译器(4.2)和没有C ++ 0x模式的情况下编译良好。
错误消息输出为:
In file included from /usr/include/boost/algorithm/string/split.hpp:15:0,
from /usr/include/boost/algorithm/string.hpp:22,
from test.cpp:1:
/usr/include/boost/algorithm/string/iter_find.hpp: In function 'SequenceSequenceT& boost::algorithm::iter_split(SequenceSequenceT&, RangeT&, FinderT) [with SequenceSequenceT = std::vector<std::basic_string<char> >, RangeT = std::basic_string<char>, FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>]':
test.cpp:15:47: instantiated from here
/usr/include/boost/algorithm/string/iter_find.hpp:154:51: error: call of overloaded 'end(std::basic_string<char>&)' is ambiguous
/usr/include/boost/algorithm/string/iter_find.hpp:154:51: note: candidates are:
/usr/include/boost/range/end.hpp:145:56: note: typename boost::range_iterator<typename boost::remove_const<T>::type>::type boost::end(T&) [with T = std::basic_string<char>, typename boost::range_iterator<typename boost::remove_const<T>::type>::type = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]
/usr/include/boost/range/end.hpp:156:61: note: typename boost::range_const_iterator<C>::type boost::end(const T&) [with T = std::basic_string<char>, typename boost::range_const_iterator<C>::type = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >]
/usr/lib/gcc/i686-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/range_access.h:78:5: note: decltype (__cont.end()) std::end(const _Container&) [with _Container = std::basic_string<char>, decltype (__cont.end()) = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >]
/usr/lib/gcc/i686-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/range_access.h:68:5: note: decltype (__cont.end()) std::end(_Container&) [with _Container = std::basic_string<char>, decltype (__cont.end()) = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]
test.cpp:15:47: instantiated from here
/usr/include/boost/algorithm/string/iter_find.hpp:162:39: error: call of overloaded 'begin(std::basic_string<char>&)' is ambiguous
/usr/include/boost/algorithm/string/iter_find.hpp:162:39: note: candidates are:
/usr/include/boost/range/begin.hpp:146:64: note: typename boost::range_iterator<typename boost::remove_const<T>::type>::type boost::begin(T&) [with T = std::basic_string<char>, typename boost::range_iterator<typename boost::remove_const<T>::type>::type = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]
/usr/include/boost/range/begin.hpp:157:61: note: typename boost::range_const_iterator<C>::type boost::begin(const T&) [with T = std::basic_string<char>, typename boost::range_const_iterator<C>::type = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >]
/usr/lib/gcc/i686-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/range_access.h:58:5: note: decltype (__cont.begin()) std::begin(const _Container&) [with _Container = std::basic_string<char>, decltype (__cont.begin()) = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char> >]
/usr/lib/gcc/i686-linux-gnu/4.6.2/../../../../include/c++/4.6.2/bits/range_access.h:48:5: note: decltype (__cont.begin()) std::begin(_Container&) [with _Container = std::basic_string<char>, decltype (__cont.begin()) = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >]
这可能是海湾合作委员会的一个错误吗?或者我可以对代码做些什么来解决这个问题?
答案 0 :(得分:2)
这只是您正在使用的超过4年的Boost版本中的一个错误。升级到更新的东西(1.48.0是最新的),你的代码将干净地编译。
答案 1 :(得分:0)
确保已安装boost-devel软件包
在Centos中以root身份执行:
yum install boost-devel
然后
root@centos6 /]# find / -name boost
/usr/include/boost
/usr/lib64/boost
[root@centos6 /]#