使用boost :: split会带来一些奇怪的错误

时间:2014-12-15 19:52:42

标签: c++ boost

#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];
}

这标志着Boost中的6个错误和std中的1个错误。我的想法是命名空间搞乱了。这是实际代码库的编辑版本,但基本上我使用boost :: gregorian作为单独的date_time事物,并为algoritm代码库提升。我看到一个例子,使用多个命名空间很好。对我来说,它只是不让我使用拆分。

1 个答案:

答案 0 :(得分:1)

您将一个字符传递给boost::is_any_of,但它需要一个序列。

更改代码: 来自:boost::is_any_of(' ') to:boost::is_any_of(" ")你应该是金色的。

(哦,是的,并在您的示例中添加#include <vector>#include <iostream>