0

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?

Karnivaurus
  • 22,823
  • 57
  • 147
  • 247

2 Answers2

1

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(","));
//                                                      ^ ^
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
0

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

Community
  • 1
  • 1
Tung
  • 1,579
  • 4
  • 15
  • 32