Using boost::split brings up a load of weird error

2019-09-18 00:59发布

问题:

#include <string>
#include "boost\date_time\gregorian\gregorian.hpp"
#include <boost\algorithm\string.hpp>

using namespace std;
using namespace boost::gregorian;
using namespace boost;


void printString()
{
vector<string> strs;
boost::split(strs, "string to split", boost::is_any_of(' '));
cout << strs[0];
}

This flags up about 6 errors in Boost and 1 in std. My thinking is the namespaces are messing up. This is an edited version of the actual code base but basically I'm using boost::gregorian for a seperate date_time thing and boost for the algoritm code base. I saw an example and using more than one namespace was fine. For me it's just not letting me use split.

回答1:

You're passing a single character to boost::is_any_of, but it expects a sequence.

Change the code from: from: boost::is_any_of(' ') to: boost::is_any_of(" ") and you should be golden.

(oh yeah, and add #include <vector> and #include <iostream> to your example.



标签: c++ boost