简体   繁体   中英

Cannot get boost header to compile

I want to use the Boost library to split a string, but I am getting a compilation error with Visual Studio.

My code has #include "boost/algorithm/string/split.hpp"; and #include "boost/algorithm/string/classification.hpp"; and my project's include directories contains C:\\Data\\Libraries\\Boost_1.56.0 , which itself contains the root boost directory with Boost's header files.

I then have the following:

std::string line = "this,is,a,test";
std::vector<std::string> strings;
boost::algorithm::split(strings, line, boost::is_any_of(','));

But this gives me all sorts of errors, such as:

Error   37  error C2039: 'type' : is not a member of 'boost::mpl::eval_if_c<false,boost::range_const_iterator<char,void>,boost::range_mutable_iterator<char,void>>' C:\Data\Libraries\Boost_1.56.0\boost\range\iterator.hpp 69

Any help?

The message is confusing because it's basically template meta-programming having a tantrum, but the problem is that boost::is_any_of(',') won't compile because ',' is a single character that cannot be treated as a "range".

You meant to write:

boost::algorithm::split(strings, line, boost::is_any_of(","));
//                                                      ^ ^

You try using boost::algorithm::split(strings, line, boost::is_any_of(",")); . Here is another explaination of using split function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM